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

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

Issue 257773008: New analyzer snapshot, based on r35422. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update pubspec.yaml Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.ast_test; 8 library engine.ast_test;
9 9
10 import 'package:analyzer/src/generated/java_core.dart'; 10 import 'package:analyzer/src/generated/java_core.dart';
11 import 'package:analyzer/src/generated/java_engine.dart'; 11 import 'package:analyzer/src/generated/java_engine.dart';
12 import 'package:analyzer/src/generated/java_junit.dart'; 12 import 'package:analyzer/src/generated/java_junit.dart';
13 import 'package:analyzer/src/generated/java_engine.dart' show Predicate; 13 import 'package:analyzer/src/generated/java_engine.dart' show Predicate;
14 import 'package:analyzer/src/generated/scanner.dart'; 14 import 'package:analyzer/src/generated/scanner.dart';
15 import 'package:analyzer/src/generated/ast.dart'; 15 import 'package:analyzer/src/generated/ast.dart';
16 import 'package:analyzer/src/generated/utilities_dart.dart'; 16 import 'package:analyzer/src/generated/utilities_dart.dart';
17 import 'package:analyzer/src/generated/element.dart' show ClassElement; 17 import 'package:analyzer/src/generated/element.dart' show ClassElement;
18 import 'package:unittest/unittest.dart' as _ut; 18 import 'package:unittest/unittest.dart' as _ut;
19 import 'parser_test.dart' show ParserTestCase; 19 import 'parser_test.dart' show ParserTestCase;
20 import 'test_support.dart'; 20 import 'test_support.dart';
21 import 'scanner_test.dart' show TokenFactory; 21 import 'scanner_test.dart' show TokenFactory;
22 22
23 class NodeLocatorTest extends ParserTestCase {
24 void test_range() {
25 CompilationUnit unit = ParserTestCase.parseCompilationUnit("library myLib;", []);
26 _assertLocate(unit, 4, 10, (node) => node is LibraryDirective, LibraryDirect ive);
27 }
28
29 void test_searchWithin_null() {
30 NodeLocator locator = new NodeLocator.con2(0, 0);
31 JUnitTestCase.assertNull(locator.searchWithin(null));
32 }
33
34 void test_searchWithin_offset() {
35 CompilationUnit unit = ParserTestCase.parseCompilationUnit("library myLib;", []);
36 _assertLocate(unit, 10, 10, (node) => node is SimpleIdentifier, SimpleIdenti fier);
37 }
38
39 void test_searchWithin_offsetAfterNode() {
40 CompilationUnit unit = ParserTestCase.parseCompilationUnit(EngineTestCase.cr eateSource(["class A {}", "class B {}"]), []);
41 NodeLocator locator = new NodeLocator.con2(1024, 1024);
42 AstNode node = locator.searchWithin(unit.declarations[0]);
43 JUnitTestCase.assertNull(node);
44 }
45
46 void test_searchWithin_offsetBeforeNode() {
47 CompilationUnit unit = ParserTestCase.parseCompilationUnit(EngineTestCase.cr eateSource(["class A {}", "class B {}"]), []);
48 NodeLocator locator = new NodeLocator.con2(0, 0);
49 AstNode node = locator.searchWithin(unit.declarations[1]);
50 JUnitTestCase.assertNull(node);
51 }
52
53 void _assertLocate(CompilationUnit unit, int start, int end, Predicate<AstNode > predicate, Type expectedClass) {
54 NodeLocator locator = new NodeLocator.con2(start, end);
55 AstNode node = locator.searchWithin(unit);
56 JUnitTestCase.assertNotNull(node);
57 JUnitTestCase.assertSame(node, locator.foundNode);
58 JUnitTestCase.assertTrueMsg("Node starts after range", node.offset <= start) ;
59 JUnitTestCase.assertTrueMsg("Node ends before range", node.offset + node.len gth > end);
60 EngineTestCase.assertInstanceOf(predicate, expectedClass, node);
61 }
62
63 static dartSuite() {
64 _ut.group('NodeLocatorTest', () {
65 _ut.test('test_range', () {
66 final __test = new NodeLocatorTest();
67 runJUnitTest(__test, __test.test_range);
68 });
69 _ut.test('test_searchWithin_null', () {
70 final __test = new NodeLocatorTest();
71 runJUnitTest(__test, __test.test_searchWithin_null);
72 });
73 _ut.test('test_searchWithin_offset', () {
74 final __test = new NodeLocatorTest();
75 runJUnitTest(__test, __test.test_searchWithin_offset);
76 });
77 _ut.test('test_searchWithin_offsetAfterNode', () {
78 final __test = new NodeLocatorTest();
79 runJUnitTest(__test, __test.test_searchWithin_offsetAfterNode);
80 });
81 _ut.test('test_searchWithin_offsetBeforeNode', () {
82 final __test = new NodeLocatorTest();
83 runJUnitTest(__test, __test.test_searchWithin_offsetBeforeNode);
84 });
85 });
86 }
87 }
88
89 class IndexExpressionTest extends EngineTestCase {
90 void test_inGetterContext_assignment_compound_left() {
91 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
92 // a[i] += ?
93 AstFactory.assignmentExpression(expression, TokenType.PLUS_EQ, null);
94 JUnitTestCase.assertTrue(expression.inGetterContext());
95 }
96
97 void test_inGetterContext_assignment_simple_left() {
98 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
99 // a[i] = ?
100 AstFactory.assignmentExpression(expression, TokenType.EQ, null);
101 JUnitTestCase.assertFalse(expression.inGetterContext());
102 }
103
104 void test_inGetterContext_nonAssignment() {
105 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
106 // a[i] + ?
107 AstFactory.binaryExpression(expression, TokenType.PLUS, null);
108 JUnitTestCase.assertTrue(expression.inGetterContext());
109 }
110
111 void test_inSetterContext_assignment_compound_left() {
112 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
113 // a[i] += ?
114 AstFactory.assignmentExpression(expression, TokenType.PLUS_EQ, null);
115 JUnitTestCase.assertTrue(expression.inSetterContext());
116 }
117
118 void test_inSetterContext_assignment_compound_right() {
119 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
120 // ? += a[i]
121 AstFactory.assignmentExpression(null, TokenType.PLUS_EQ, expression);
122 JUnitTestCase.assertFalse(expression.inSetterContext());
123 }
124
125 void test_inSetterContext_assignment_simple_left() {
126 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
127 // a[i] = ?
128 AstFactory.assignmentExpression(expression, TokenType.EQ, null);
129 JUnitTestCase.assertTrue(expression.inSetterContext());
130 }
131
132 void test_inSetterContext_assignment_simple_right() {
133 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
134 // ? = a[i]
135 AstFactory.assignmentExpression(null, TokenType.EQ, expression);
136 JUnitTestCase.assertFalse(expression.inSetterContext());
137 }
138
139 void test_inSetterContext_nonAssignment() {
140 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
141 AstFactory.binaryExpression(expression, TokenType.PLUS, null);
142 // a[i] + ?
143 JUnitTestCase.assertFalse(expression.inSetterContext());
144 }
145
146 void test_inSetterContext_postfix() {
147 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
148 AstFactory.postfixExpression(expression, TokenType.PLUS_PLUS);
149 // a[i]++
150 JUnitTestCase.assertTrue(expression.inSetterContext());
151 }
152
153 void test_inSetterContext_prefix_bang() {
154 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
155 // !a[i]
156 AstFactory.prefixExpression(TokenType.BANG, expression);
157 JUnitTestCase.assertFalse(expression.inSetterContext());
158 }
159
160 void test_inSetterContext_prefix_minusMinus() {
161 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
162 // --a[i]
163 AstFactory.prefixExpression(TokenType.MINUS_MINUS, expression);
164 JUnitTestCase.assertTrue(expression.inSetterContext());
165 }
166
167 void test_inSetterContext_prefix_plusPlus() {
168 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
169 // ++a[i]
170 AstFactory.prefixExpression(TokenType.PLUS_PLUS, expression);
171 JUnitTestCase.assertTrue(expression.inSetterContext());
172 }
173
174 static dartSuite() {
175 _ut.group('IndexExpressionTest', () {
176 _ut.test('test_inGetterContext_assignment_compound_left', () {
177 final __test = new IndexExpressionTest();
178 runJUnitTest(__test, __test.test_inGetterContext_assignment_compound_lef t);
179 });
180 _ut.test('test_inGetterContext_assignment_simple_left', () {
181 final __test = new IndexExpressionTest();
182 runJUnitTest(__test, __test.test_inGetterContext_assignment_simple_left) ;
183 });
184 _ut.test('test_inGetterContext_nonAssignment', () {
185 final __test = new IndexExpressionTest();
186 runJUnitTest(__test, __test.test_inGetterContext_nonAssignment);
187 });
188 _ut.test('test_inSetterContext_assignment_compound_left', () {
189 final __test = new IndexExpressionTest();
190 runJUnitTest(__test, __test.test_inSetterContext_assignment_compound_lef t);
191 });
192 _ut.test('test_inSetterContext_assignment_compound_right', () {
193 final __test = new IndexExpressionTest();
194 runJUnitTest(__test, __test.test_inSetterContext_assignment_compound_rig ht);
195 });
196 _ut.test('test_inSetterContext_assignment_simple_left', () {
197 final __test = new IndexExpressionTest();
198 runJUnitTest(__test, __test.test_inSetterContext_assignment_simple_left) ;
199 });
200 _ut.test('test_inSetterContext_assignment_simple_right', () {
201 final __test = new IndexExpressionTest();
202 runJUnitTest(__test, __test.test_inSetterContext_assignment_simple_right );
203 });
204 _ut.test('test_inSetterContext_nonAssignment', () {
205 final __test = new IndexExpressionTest();
206 runJUnitTest(__test, __test.test_inSetterContext_nonAssignment);
207 });
208 _ut.test('test_inSetterContext_postfix', () {
209 final __test = new IndexExpressionTest();
210 runJUnitTest(__test, __test.test_inSetterContext_postfix);
211 });
212 _ut.test('test_inSetterContext_prefix_bang', () {
213 final __test = new IndexExpressionTest();
214 runJUnitTest(__test, __test.test_inSetterContext_prefix_bang);
215 });
216 _ut.test('test_inSetterContext_prefix_minusMinus', () {
217 final __test = new IndexExpressionTest();
218 runJUnitTest(__test, __test.test_inSetterContext_prefix_minusMinus);
219 });
220 _ut.test('test_inSetterContext_prefix_plusPlus', () {
221 final __test = new IndexExpressionTest();
222 runJUnitTest(__test, __test.test_inSetterContext_prefix_plusPlus);
223 });
224 });
225 }
226 }
227
228 class ClassDeclarationTest extends ParserTestCase {
229 void test_getConstructor() {
230 List<ConstructorInitializer> initializers = new List<ConstructorInitializer> ();
231 ConstructorDeclaration defaultConstructor = AstFactory.constructorDeclaratio n(AstFactory.identifier3("Test"), null, AstFactory.formalParameterList([]), init ializers);
232 ConstructorDeclaration aConstructor = AstFactory.constructorDeclaration(AstF actory.identifier3("Test"), "a", AstFactory.formalParameterList([]), initializer s);
233 ConstructorDeclaration bConstructor = AstFactory.constructorDeclaration(AstF actory.identifier3("Test"), "b", AstFactory.formalParameterList([]), initializer s);
234 ClassDeclaration clazz = AstFactory.classDeclaration(null, "Test", null, nul l, null, null, [defaultConstructor, aConstructor, bConstructor]);
235 JUnitTestCase.assertSame(defaultConstructor, clazz.getConstructor(null));
236 JUnitTestCase.assertSame(aConstructor, clazz.getConstructor("a"));
237 JUnitTestCase.assertSame(bConstructor, clazz.getConstructor("b"));
238 JUnitTestCase.assertSame(null, clazz.getConstructor("noSuchConstructor"));
239 }
240
241 void test_getField() {
242 VariableDeclaration aVar = AstFactory.variableDeclaration("a");
243 VariableDeclaration bVar = AstFactory.variableDeclaration("b");
244 VariableDeclaration cVar = AstFactory.variableDeclaration("c");
245 ClassDeclaration clazz = AstFactory.classDeclaration(null, "Test", null, nul l, null, null, [
246 AstFactory.fieldDeclaration2(false, null, [aVar]),
247 AstFactory.fieldDeclaration2(false, null, [bVar, cVar])]);
248 JUnitTestCase.assertSame(aVar, clazz.getField("a"));
249 JUnitTestCase.assertSame(bVar, clazz.getField("b"));
250 JUnitTestCase.assertSame(cVar, clazz.getField("c"));
251 JUnitTestCase.assertSame(null, clazz.getField("noSuchField"));
252 }
253
254 void test_getMethod() {
255 MethodDeclaration aMethod = AstFactory.methodDeclaration(null, null, null, n ull, AstFactory.identifier3("a"), AstFactory.formalParameterList([]));
256 MethodDeclaration bMethod = AstFactory.methodDeclaration(null, null, null, n ull, AstFactory.identifier3("b"), AstFactory.formalParameterList([]));
257 ClassDeclaration clazz = AstFactory.classDeclaration(null, "Test", null, nul l, null, null, [aMethod, bMethod]);
258 JUnitTestCase.assertSame(aMethod, clazz.getMethod("a"));
259 JUnitTestCase.assertSame(bMethod, clazz.getMethod("b"));
260 JUnitTestCase.assertSame(null, clazz.getMethod("noSuchMethod"));
261 }
262
263 void test_isAbstract() {
264 JUnitTestCase.assertFalse(AstFactory.classDeclaration(null, "A", null, null, null, null, []).isAbstract);
265 JUnitTestCase.assertTrue(AstFactory.classDeclaration(Keyword.ABSTRACT, "B", null, null, null, null, []).isAbstract);
266 }
267
268 static dartSuite() {
269 _ut.group('ClassDeclarationTest', () {
270 _ut.test('test_getConstructor', () {
271 final __test = new ClassDeclarationTest();
272 runJUnitTest(__test, __test.test_getConstructor);
273 });
274 _ut.test('test_getField', () {
275 final __test = new ClassDeclarationTest();
276 runJUnitTest(__test, __test.test_getField);
277 });
278 _ut.test('test_getMethod', () {
279 final __test = new ClassDeclarationTest();
280 runJUnitTest(__test, __test.test_getMethod);
281 });
282 _ut.test('test_isAbstract', () {
283 final __test = new ClassDeclarationTest();
284 runJUnitTest(__test, __test.test_isAbstract);
285 });
286 });
287 }
288 }
289
290 class VariableDeclarationTest extends ParserTestCase {
291 void test_getDocumentationComment_onGrandParent() {
292 VariableDeclaration varDecl = AstFactory.variableDeclaration("a");
293 TopLevelVariableDeclaration decl = AstFactory.topLevelVariableDeclaration2(K eyword.VAR, [varDecl]);
294 Comment comment = Comment.createDocumentationComment(new List<Token>(0));
295 JUnitTestCase.assertNull(varDecl.documentationComment);
296 decl.documentationComment = comment;
297 JUnitTestCase.assertNotNull(varDecl.documentationComment);
298 JUnitTestCase.assertNotNull(decl.documentationComment);
299 }
300
301 void test_getDocumentationComment_onNode() {
302 VariableDeclaration decl = AstFactory.variableDeclaration("a");
303 Comment comment = Comment.createDocumentationComment(new List<Token>(0));
304 decl.documentationComment = comment;
305 JUnitTestCase.assertNotNull(decl.documentationComment);
306 }
307
308 static dartSuite() {
309 _ut.group('VariableDeclarationTest', () {
310 _ut.test('test_getDocumentationComment_onGrandParent', () {
311 final __test = new VariableDeclarationTest();
312 runJUnitTest(__test, __test.test_getDocumentationComment_onGrandParent);
313 });
314 _ut.test('test_getDocumentationComment_onNode', () {
315 final __test = new VariableDeclarationTest();
316 runJUnitTest(__test, __test.test_getDocumentationComment_onNode);
317 });
318 });
319 }
320 }
321
322 /**
323 * The class `AstFactory` defines utility methods that can be used to create AST nodes. The
324 * nodes that are created are complete in the sense that all of the tokens that would have been
325 * associated with the nodes by a parser are also created, but the token stream is not constructed.
326 * None of the nodes are resolved.
327 *
328 * The general pattern is for the name of the factory method to be the same as t he name of the class
329 * of AST node being created. There are two notable exceptions. The first is for methods creating
330 * nodes that are part of a cascade expression. These methods are all prefixed w ith 'cascaded'. The
331 * second is places where a shorter name seemed unambiguous and easier to read, such as using
332 * 'identifier' rather than 'prefixedIdentifier', or 'integer' rather than 'inte gerLiteral'.
333 */
334 class AstFactory {
335 static AdjacentStrings adjacentStrings(List<StringLiteral> strings) => new Adj acentStrings(list(strings));
336
337 static Annotation annotation(Identifier name) => new Annotation(TokenFactory.t okenFromType(TokenType.AT), name, null, null, null);
338
339 static Annotation annotation2(Identifier name, SimpleIdentifier constructorNam e, ArgumentList arguments) => new Annotation(TokenFactory.tokenFromType(TokenTyp e.AT), name, TokenFactory.tokenFromType(TokenType.PERIOD), constructorName, argu ments);
340
341 static ArgumentDefinitionTest argumentDefinitionTest(String identifier) => new ArgumentDefinitionTest(TokenFactory.tokenFromType(TokenType.QUESTION), identifi er3(identifier));
342
343 static ArgumentList argumentList(List<Expression> arguments) => new ArgumentLi st(TokenFactory.tokenFromType(TokenType.OPEN_PAREN), list(arguments), TokenFacto ry.tokenFromType(TokenType.CLOSE_PAREN));
344
345 static AsExpression asExpression(Expression expression, TypeName type) => new AsExpression(expression, TokenFactory.tokenFromKeyword(Keyword.AS), type);
346
347 static AssertStatement assertStatement(Expression condition) => new AssertStat ement(TokenFactory.tokenFromKeyword(Keyword.ASSERT), TokenFactory.tokenFromType( TokenType.OPEN_PAREN), condition, TokenFactory.tokenFromType(TokenType.CLOSE_PAR EN), TokenFactory.tokenFromType(TokenType.SEMICOLON));
348
349 static AssignmentExpression assignmentExpression(Expression leftHandSide, Toke nType operator, Expression rightHandSide) => new AssignmentExpression(leftHandSi de, TokenFactory.tokenFromType(operator), rightHandSide);
350
351 static BinaryExpression binaryExpression(Expression leftOperand, TokenType ope rator, Expression rightOperand) => new BinaryExpression(leftOperand, TokenFactor y.tokenFromType(operator), rightOperand);
352
353 static Block block(List<Statement> statements) => new Block(TokenFactory.token FromType(TokenType.OPEN_CURLY_BRACKET), list(statements), TokenFactory.tokenFrom Type(TokenType.CLOSE_CURLY_BRACKET));
354
355 static BlockFunctionBody blockFunctionBody(Block block) => new BlockFunctionBo dy(block);
356
357 static BlockFunctionBody blockFunctionBody2(List<Statement> statements) => new BlockFunctionBody(block(statements));
358
359 static BooleanLiteral booleanLiteral(bool value) => new BooleanLiteral(value ? TokenFactory.tokenFromKeyword(Keyword.TRUE) : TokenFactory.tokenFromKeyword(Key word.FALSE), value);
360
361 static BreakStatement breakStatement() => new BreakStatement(TokenFactory.toke nFromKeyword(Keyword.BREAK), null, TokenFactory.tokenFromType(TokenType.SEMICOLO N));
362
363 static BreakStatement breakStatement2(String label) => new BreakStatement(Toke nFactory.tokenFromKeyword(Keyword.BREAK), identifier3(label), TokenFactory.token FromType(TokenType.SEMICOLON));
364
365 static IndexExpression cascadedIndexExpression(Expression index) => new IndexE xpression.forCascade(TokenFactory.tokenFromType(TokenType.PERIOD_PERIOD), TokenF actory.tokenFromType(TokenType.OPEN_SQUARE_BRACKET), index, TokenFactory.tokenFr omType(TokenType.CLOSE_SQUARE_BRACKET));
366
367 static MethodInvocation cascadedMethodInvocation(String methodName, List<Expre ssion> arguments) => new MethodInvocation(null, TokenFactory.tokenFromType(Token Type.PERIOD_PERIOD), identifier3(methodName), argumentList(arguments));
368
369 static PropertyAccess cascadedPropertyAccess(String propertyName) => new Prope rtyAccess(null, TokenFactory.tokenFromType(TokenType.PERIOD_PERIOD), identifier3 (propertyName));
370
371 static CascadeExpression cascadeExpression(Expression target, List<Expression> cascadeSections) => new CascadeExpression(target, list(cascadeSections));
372
373 static CatchClause catchClause(String exceptionParameter, List<Statement> stat ements) => catchClause5(null, exceptionParameter, null, statements);
374
375 static CatchClause catchClause2(String exceptionParameter, String stackTracePa rameter, List<Statement> statements) => catchClause5(null, exceptionParameter, s tackTraceParameter, statements);
376
377 static CatchClause catchClause3(TypeName exceptionType, List<Statement> statem ents) => catchClause5(exceptionType, null, null, statements);
378
379 static CatchClause catchClause4(TypeName exceptionType, String exceptionParame ter, List<Statement> statements) => catchClause5(exceptionType, exceptionParamet er, null, statements);
380
381 static CatchClause catchClause5(TypeName exceptionType, String exceptionParame ter, String stackTraceParameter, List<Statement> statements) => new CatchClause( exceptionType == null ? null : TokenFactory.tokenFromTypeAndString(TokenType.IDE NTIFIER, "on"), exceptionType, exceptionParameter == null ? null : TokenFactory. tokenFromKeyword(Keyword.CATCH), exceptionParameter == null ? null : TokenFactor y.tokenFromType(TokenType.OPEN_PAREN), exceptionParameter == null ? null : ident ifier3(exceptionParameter), stackTraceParameter == null ? null : TokenFactory.to kenFromType(TokenType.COMMA), stackTraceParameter == null ? null : identifier3(s tackTraceParameter), exceptionParameter == null ? null : TokenFactory.tokenFromT ype(TokenType.CLOSE_PAREN), block(statements));
382
383 static ClassDeclaration classDeclaration(Keyword abstractKeyword, String name, TypeParameterList typeParameters, ExtendsClause extendsClause, WithClause withC lause, ImplementsClause implementsClause, List<ClassMember> members) => new Clas sDeclaration(null, null, abstractKeyword == null ? null : TokenFactory.tokenFrom Keyword(abstractKeyword), TokenFactory.tokenFromKeyword(Keyword.CLASS), identifi er3(name), typeParameters, extendsClause, withClause, implementsClause, TokenFac tory.tokenFromType(TokenType.OPEN_CURLY_BRACKET), list(members), TokenFactory.to kenFromType(TokenType.CLOSE_CURLY_BRACKET));
384
385 static ClassTypeAlias classTypeAlias(String name, TypeParameterList typeParame ters, Keyword abstractKeyword, TypeName superclass, WithClause withClause, Imple mentsClause implementsClause) => new ClassTypeAlias(null, null, TokenFactory.tok enFromKeyword(Keyword.CLASS), identifier3(name), typeParameters, TokenFactory.to kenFromType(TokenType.EQ), abstractKeyword == null ? null : TokenFactory.tokenFr omKeyword(abstractKeyword), superclass, withClause, implementsClause, TokenFacto ry.tokenFromType(TokenType.SEMICOLON));
386
387 static CompilationUnit compilationUnit() => compilationUnit8(null, null, null) ;
388
389 static CompilationUnit compilationUnit2(List<CompilationUnitMember> declaratio ns) => compilationUnit8(null, null, list(declarations));
390
391 static CompilationUnit compilationUnit3(List<Directive> directives) => compila tionUnit8(null, list(directives), null);
392
393 static CompilationUnit compilationUnit4(List<Directive> directives, List<Compi lationUnitMember> declarations) => compilationUnit8(null, directives, declaratio ns);
394
395 static CompilationUnit compilationUnit5(String scriptTag) => compilationUnit8( scriptTag, null, null);
396
397 static CompilationUnit compilationUnit6(String scriptTag, List<CompilationUnit Member> declarations) => compilationUnit8(scriptTag, null, list(declarations));
398
399 static CompilationUnit compilationUnit7(String scriptTag, List<Directive> dire ctives) => compilationUnit8(scriptTag, list(directives), null);
400
401 static CompilationUnit compilationUnit8(String scriptTag, List<Directive> dire ctives, List<CompilationUnitMember> declarations) => new CompilationUnit(TokenFa ctory.tokenFromType(TokenType.EOF), scriptTag == null ? null : AstFactory.script Tag(scriptTag), directives == null ? new List<Directive>() : directives, declara tions == null ? new List<CompilationUnitMember>() : declarations, TokenFactory.t okenFromType(TokenType.EOF));
402
403 static ConditionalExpression conditionalExpression(Expression condition, Expre ssion thenExpression, Expression elseExpression) => new ConditionalExpression(co ndition, TokenFactory.tokenFromType(TokenType.QUESTION), thenExpression, TokenFa ctory.tokenFromType(TokenType.COLON), elseExpression);
404
405 static ConstructorDeclaration constructorDeclaration(Identifier returnType, St ring name, FormalParameterList parameters, List<ConstructorInitializer> initiali zers) => new ConstructorDeclaration(null, null, TokenFactory.tokenFromKeyword(Ke yword.EXTERNAL), null, null, returnType, name == null ? null : TokenFactory.toke nFromType(TokenType.PERIOD), name == null ? null : identifier3(name), parameters , initializers == null || initializers.isEmpty ? null : TokenFactory.tokenFromTy pe(TokenType.PERIOD), initializers == null ? new List<ConstructorInitializer>() : initializers, null, emptyFunctionBody());
406
407 static ConstructorDeclaration constructorDeclaration2(Keyword constKeyword, Ke yword factoryKeyword, Identifier returnType, String name, FormalParameterList pa rameters, List<ConstructorInitializer> initializers, FunctionBody body) => new C onstructorDeclaration(null, null, null, constKeyword == null ? null : TokenFacto ry.tokenFromKeyword(constKeyword), factoryKeyword == null ? null : TokenFactory. tokenFromKeyword(factoryKeyword), returnType, name == null ? null : TokenFactory .tokenFromType(TokenType.PERIOD), name == null ? null : identifier3(name), param eters, initializers == null || initializers.isEmpty ? null : TokenFactory.tokenF romType(TokenType.PERIOD), initializers == null ? new List<ConstructorInitialize r>() : initializers, null, body);
408
409 static ConstructorFieldInitializer constructorFieldInitializer(bool prefixedWi thThis, String fieldName, Expression expression) => new ConstructorFieldInitiali zer(prefixedWithThis ? TokenFactory.tokenFromKeyword(Keyword.THIS) : null, prefi xedWithThis ? TokenFactory.tokenFromType(TokenType.PERIOD) : null, identifier3(f ieldName), TokenFactory.tokenFromType(TokenType.EQ), expression);
410
411 static ConstructorName constructorName(TypeName type, String name) => new Cons tructorName(type, name == null ? null : TokenFactory.tokenFromType(TokenType.PER IOD), name == null ? null : identifier3(name));
412
413 static ContinueStatement continueStatement([String label]) {
414 SimpleIdentifier labelNode = label == null ? null : identifier3(label);
415 return new ContinueStatement(TokenFactory.tokenFromKeyword(Keyword.CONTINUE) , labelNode, TokenFactory.tokenFromType(TokenType.SEMICOLON));
416 }
417
418 static DeclaredIdentifier declaredIdentifier(Keyword keyword, String identifie r) => declaredIdentifier2(keyword, null, identifier);
419
420 static DeclaredIdentifier declaredIdentifier2(Keyword keyword, TypeName type, String identifier) => new DeclaredIdentifier(null, null, keyword == null ? null : TokenFactory.tokenFromKeyword(keyword), type, identifier3(identifier));
421
422 static DeclaredIdentifier declaredIdentifier3(String identifier) => declaredId entifier2(null, null, identifier);
423
424 static DeclaredIdentifier declaredIdentifier4(TypeName type, String identifier ) => declaredIdentifier2(null, type, identifier);
425
426 static DoStatement doStatement(Statement body, Expression condition) => new Do Statement(TokenFactory.tokenFromKeyword(Keyword.DO), body, TokenFactory.tokenFro mKeyword(Keyword.WHILE), TokenFactory.tokenFromType(TokenType.OPEN_PAREN), condi tion, TokenFactory.tokenFromType(TokenType.CLOSE_PAREN), TokenFactory.tokenFromT ype(TokenType.SEMICOLON));
427
428 static DoubleLiteral doubleLiteral(double value) => new DoubleLiteral(TokenFac tory.tokenFromString(value.toString()), value);
429
430 static EmptyFunctionBody emptyFunctionBody() => new EmptyFunctionBody(TokenFac tory.tokenFromType(TokenType.SEMICOLON));
431
432 static EmptyStatement emptyStatement() => new EmptyStatement(TokenFactory.toke nFromType(TokenType.SEMICOLON));
433
434 static ExportDirective exportDirective(List<Annotation> metadata, String uri, List<Combinator> combinators) => new ExportDirective(null, metadata, TokenFactor y.tokenFromKeyword(Keyword.EXPORT), string2(uri), list(combinators), TokenFactor y.tokenFromType(TokenType.SEMICOLON));
435
436 static ExportDirective exportDirective2(String uri, List<Combinator> combinato rs) => exportDirective(new List<Annotation>(), uri, combinators);
437
438 static ExpressionFunctionBody expressionFunctionBody(Expression expression) => new ExpressionFunctionBody(TokenFactory.tokenFromType(TokenType.FUNCTION), expr ession, TokenFactory.tokenFromType(TokenType.SEMICOLON));
439
440 static ExpressionStatement expressionStatement(Expression expression) => new E xpressionStatement(expression, TokenFactory.tokenFromType(TokenType.SEMICOLON));
441
442 static ExtendsClause extendsClause(TypeName type) => new ExtendsClause(TokenFa ctory.tokenFromKeyword(Keyword.EXTENDS), type);
443
444 static FieldDeclaration fieldDeclaration(bool isStatic, Keyword keyword, TypeN ame type, List<VariableDeclaration> variables) => new FieldDeclaration(null, nul l, isStatic ? TokenFactory.tokenFromKeyword(Keyword.STATIC) : null, variableDecl arationList(keyword, type, variables), TokenFactory.tokenFromType(TokenType.SEMI COLON));
445
446 static FieldDeclaration fieldDeclaration2(bool isStatic, Keyword keyword, List <VariableDeclaration> variables) => fieldDeclaration(isStatic, keyword, null, va riables);
447
448 static FieldFormalParameter fieldFormalParameter(Keyword keyword, TypeName typ e, String identifier, [FormalParameterList parameterList]) => new FieldFormalPar ameter(null, null, keyword == null ? null : TokenFactory.tokenFromKeyword(keywor d), type, TokenFactory.tokenFromKeyword(Keyword.THIS), TokenFactory.tokenFromTyp e(TokenType.PERIOD), identifier3(identifier), parameterList);
449
450 static FieldFormalParameter fieldFormalParameter2(String identifier) => fieldF ormalParameter(null, null, identifier);
451
452 static ForEachStatement forEachStatement(DeclaredIdentifier loopVariable, Expr ession iterator, Statement body) => new ForEachStatement.con1(TokenFactory.token FromKeyword(Keyword.FOR), TokenFactory.tokenFromType(TokenType.OPEN_PAREN), loop Variable, TokenFactory.tokenFromKeyword(Keyword.IN), iterator, TokenFactory.toke nFromType(TokenType.CLOSE_PAREN), body);
453
454 static FormalParameterList formalParameterList(List<FormalParameter> parameter s) => new FormalParameterList(TokenFactory.tokenFromType(TokenType.OPEN_PAREN), list(parameters), null, null, TokenFactory.tokenFromType(TokenType.CLOSE_PAREN)) ;
455
456 static ForStatement forStatement(Expression initialization, Expression conditi on, List<Expression> updaters, Statement body) => new ForStatement(TokenFactory. tokenFromKeyword(Keyword.FOR), TokenFactory.tokenFromType(TokenType.OPEN_PAREN), null, initialization, TokenFactory.tokenFromType(TokenType.SEMICOLON), conditio n, TokenFactory.tokenFromType(TokenType.SEMICOLON), updaters, TokenFactory.token FromType(TokenType.CLOSE_PAREN), body);
457
458 static ForStatement forStatement2(VariableDeclarationList variableList, Expres sion condition, List<Expression> updaters, Statement body) => new ForStatement(T okenFactory.tokenFromKeyword(Keyword.FOR), TokenFactory.tokenFromType(TokenType. OPEN_PAREN), variableList, null, TokenFactory.tokenFromType(TokenType.SEMICOLON) , condition, TokenFactory.tokenFromType(TokenType.SEMICOLON), updaters, TokenFac tory.tokenFromType(TokenType.CLOSE_PAREN), body);
459
460 static FunctionDeclaration functionDeclaration(TypeName type, Keyword keyword, String name, FunctionExpression functionExpression) => new FunctionDeclaration( null, null, null, type, keyword == null ? null : TokenFactory.tokenFromKeyword(k eyword), identifier3(name), functionExpression);
461
462 static FunctionDeclarationStatement functionDeclarationStatement(TypeName type , Keyword keyword, String name, FunctionExpression functionExpression) => new Fu nctionDeclarationStatement(functionDeclaration(type, keyword, name, functionExpr ession));
463
464 static FunctionExpression functionExpression() => new FunctionExpression(forma lParameterList([]), blockFunctionBody2([]));
465
466 static FunctionExpression functionExpression2(FormalParameterList parameters, FunctionBody body) => new FunctionExpression(parameters, body);
467
468 static FunctionExpressionInvocation functionExpressionInvocation(Expression fu nction, List<Expression> arguments) => new FunctionExpressionInvocation(function , argumentList(arguments));
469
470 static FunctionTypedFormalParameter functionTypedFormalParameter(TypeName retu rnType, String identifier, List<FormalParameter> parameters) => new FunctionType dFormalParameter(null, null, returnType, identifier3(identifier), formalParamete rList(parameters));
471
472 static HideCombinator hideCombinator(List<SimpleIdentifier> identifiers) => ne w HideCombinator(TokenFactory.tokenFromString("hide"), list(identifiers));
473
474 static HideCombinator hideCombinator2(List<String> identifiers) {
475 List<SimpleIdentifier> identifierList = new List<SimpleIdentifier>();
476 for (String identifier in identifiers) {
477 identifierList.add(identifier3(identifier));
478 }
479 return new HideCombinator(TokenFactory.tokenFromString("hide"), identifierLi st);
480 }
481
482 static PrefixedIdentifier identifier(SimpleIdentifier prefix, SimpleIdentifier identifier) => new PrefixedIdentifier(prefix, TokenFactory.tokenFromType(TokenT ype.PERIOD), identifier);
483
484 static SimpleIdentifier identifier3(String lexeme) => new SimpleIdentifier(Tok enFactory.tokenFromTypeAndString(TokenType.IDENTIFIER, lexeme));
485
486 static PrefixedIdentifier identifier4(String prefix, SimpleIdentifier identifi er) => new PrefixedIdentifier(identifier3(prefix), TokenFactory.tokenFromType(To kenType.PERIOD), identifier);
487
488 static PrefixedIdentifier identifier5(String prefix, String identifier) => new PrefixedIdentifier(identifier3(prefix), TokenFactory.tokenFromType(TokenType.PE RIOD), identifier3(identifier));
489
490 static IfStatement ifStatement(Expression condition, Statement thenStatement) => ifStatement2(condition, thenStatement, null);
491
492 static IfStatement ifStatement2(Expression condition, Statement thenStatement, Statement elseStatement) => new IfStatement(TokenFactory.tokenFromKeyword(Keywo rd.IF), TokenFactory.tokenFromType(TokenType.OPEN_PAREN), condition, TokenFactor y.tokenFromType(TokenType.CLOSE_PAREN), thenStatement, elseStatement == null ? n ull : TokenFactory.tokenFromKeyword(Keyword.ELSE), elseStatement);
493
494 static ImplementsClause implementsClause(List<TypeName> types) => new Implemen tsClause(TokenFactory.tokenFromKeyword(Keyword.IMPLEMENTS), list(types));
495
496 static ImportDirective importDirective(List<Annotation> metadata, String uri, String prefix, List<Combinator> combinators) => new ImportDirective(null, metada ta, TokenFactory.tokenFromKeyword(Keyword.IMPORT), string2(uri), null, prefix == null ? null : TokenFactory.tokenFromKeyword(Keyword.AS), prefix == null ? null : identifier3(prefix), list(combinators), TokenFactory.tokenFromType(TokenType.S EMICOLON));
497
498 static ImportDirective importDirective2(String uri, String prefix, List<Combin ator> combinators) => importDirective(new List<Annotation>(), uri, prefix, combi nators);
499
500 static IndexExpression indexExpression(Expression array, Expression index) => new IndexExpression.forTarget(array, TokenFactory.tokenFromType(TokenType.OPEN_S QUARE_BRACKET), index, TokenFactory.tokenFromType(TokenType.CLOSE_SQUARE_BRACKET ));
501
502 static InstanceCreationExpression instanceCreationExpression(Keyword keyword, ConstructorName name, List<Expression> arguments) => new InstanceCreationExpress ion(keyword == null ? null : TokenFactory.tokenFromKeyword(keyword), name, argum entList(arguments));
503
504 static InstanceCreationExpression instanceCreationExpression2(Keyword keyword, TypeName type, List<Expression> arguments) => instanceCreationExpression3(keywo rd, type, null, arguments);
505
506 static InstanceCreationExpression instanceCreationExpression3(Keyword keyword, TypeName type, String identifier, List<Expression> arguments) => instanceCreati onExpression(keyword, new ConstructorName(type, identifier == null ? null : Toke nFactory.tokenFromType(TokenType.PERIOD), identifier == null ? null : identifier 3(identifier)), arguments);
507
508 static IntegerLiteral integer(int value) => new IntegerLiteral(TokenFactory.to kenFromTypeAndString(TokenType.INT, value.toString()), value);
509
510 static InterpolationExpression interpolationExpression(Expression expression) => new InterpolationExpression(TokenFactory.tokenFromType(TokenType.STRING_INTER POLATION_EXPRESSION), expression, TokenFactory.tokenFromType(TokenType.CLOSE_CUR LY_BRACKET));
511
512 static InterpolationExpression interpolationExpression2(String identifier) => new InterpolationExpression(TokenFactory.tokenFromType(TokenType.STRING_INTERPOL ATION_IDENTIFIER), identifier3(identifier), null);
513
514 static InterpolationString interpolationString(String contents, String value) => new InterpolationString(TokenFactory.tokenFromString(contents), value);
515
516 static IsExpression isExpression(Expression expression, bool negated, TypeName type) => new IsExpression(expression, TokenFactory.tokenFromKeyword(Keyword.IS) , negated ? TokenFactory.tokenFromType(TokenType.BANG) : null, type);
517
518 static Label label(SimpleIdentifier label) => new Label(label, TokenFactory.to kenFromType(TokenType.COLON));
519
520 static Label label2(String label) => AstFactory.label(identifier3(label));
521
522 static LabeledStatement labeledStatement(List<Label> labels, Statement stateme nt) => new LabeledStatement(labels, statement);
523
524 static LibraryDirective libraryDirective(List<Annotation> metadata, LibraryIde ntifier libraryName) => new LibraryDirective(null, metadata, TokenFactory.tokenF romKeyword(Keyword.LIBRARY), libraryName, TokenFactory.tokenFromType(TokenType.S EMICOLON));
525
526 static LibraryDirective libraryDirective2(String libraryName) => libraryDirect ive(new List<Annotation>(), libraryIdentifier2([libraryName]));
527
528 static LibraryIdentifier libraryIdentifier(List<SimpleIdentifier> components) => new LibraryIdentifier(list(components));
529
530 static LibraryIdentifier libraryIdentifier2(List<String> components) {
531 List<SimpleIdentifier> componentList = new List<SimpleIdentifier>();
532 for (String component in components) {
533 componentList.add(identifier3(component));
534 }
535 return new LibraryIdentifier(componentList);
536 }
537
538 static List list(List<Object> elements) {
539 List elementList = new List();
540 for (Object element in elements) {
541 elementList.add(element);
542 }
543 return elementList;
544 }
545
546 static ListLiteral listLiteral(List<Expression> elements) => listLiteral2(null , null, elements);
547
548 static ListLiteral listLiteral2(Keyword keyword, TypeArgumentList typeArgument s, List<Expression> elements) => new ListLiteral(keyword == null ? null : TokenF actory.tokenFromKeyword(keyword), null, TokenFactory.tokenFromType(TokenType.OPE N_SQUARE_BRACKET), list(elements), TokenFactory.tokenFromType(TokenType.CLOSE_SQ UARE_BRACKET));
549
550 static MapLiteral mapLiteral(Keyword keyword, TypeArgumentList typeArguments, List<MapLiteralEntry> entries) => new MapLiteral(keyword == null ? null : TokenF actory.tokenFromKeyword(keyword), typeArguments, TokenFactory.tokenFromType(Toke nType.OPEN_CURLY_BRACKET), list(entries), TokenFactory.tokenFromType(TokenType.C LOSE_CURLY_BRACKET));
551
552 static MapLiteral mapLiteral2(List<MapLiteralEntry> entries) => mapLiteral(nul l, null, entries);
553
554 static MapLiteralEntry mapLiteralEntry(String key, Expression value) => new Ma pLiteralEntry(string2(key), TokenFactory.tokenFromType(TokenType.COLON), value);
555
556 static MethodDeclaration methodDeclaration(Keyword modifier, TypeName returnTy pe, Keyword property, Keyword operator, SimpleIdentifier name, FormalParameterLi st parameters) => new MethodDeclaration(null, null, TokenFactory.tokenFromKeywor d(Keyword.EXTERNAL), modifier == null ? null : TokenFactory.tokenFromKeyword(mod ifier), returnType, property == null ? null : TokenFactory.tokenFromKeyword(prop erty), operator == null ? null : TokenFactory.tokenFromKeyword(operator), name, parameters, emptyFunctionBody());
557
558 static MethodDeclaration methodDeclaration2(Keyword modifier, TypeName returnT ype, Keyword property, Keyword operator, SimpleIdentifier name, FormalParameterL ist parameters, FunctionBody body) => new MethodDeclaration(null, null, null, mo difier == null ? null : TokenFactory.tokenFromKeyword(modifier), returnType, pro perty == null ? null : TokenFactory.tokenFromKeyword(property), operator == null ? null : TokenFactory.tokenFromKeyword(operator), name, parameters, body);
559
560 static MethodInvocation methodInvocation(Expression target, String methodName, List<Expression> arguments) => new MethodInvocation(target, target == null ? nu ll : TokenFactory.tokenFromType(TokenType.PERIOD), identifier3(methodName), argu mentList(arguments));
561
562 static MethodInvocation methodInvocation2(String methodName, List<Expression> arguments) => methodInvocation(null, methodName, arguments);
563
564 static NamedExpression namedExpression(Label label, Expression expression) => new NamedExpression(label, expression);
565
566 static NamedExpression namedExpression2(String label, Expression expression) = > namedExpression(label2(label), expression);
567
568 static DefaultFormalParameter namedFormalParameter(NormalFormalParameter param eter, Expression expression) => new DefaultFormalParameter(parameter, ParameterK ind.NAMED, expression == null ? null : TokenFactory.tokenFromType(TokenType.COLO N), expression);
569
570 static NativeClause nativeClause(String nativeCode) => new NativeClause(TokenF actory.tokenFromString("native"), string2(nativeCode));
571
572 static NativeFunctionBody nativeFunctionBody(String nativeMethodName) => new N ativeFunctionBody(TokenFactory.tokenFromString("native"), string2(nativeMethodNa me), TokenFactory.tokenFromType(TokenType.SEMICOLON));
573
574 static NullLiteral nullLiteral() => new NullLiteral(TokenFactory.tokenFromKeyw ord(Keyword.NULL));
575
576 static ParenthesizedExpression parenthesizedExpression(Expression expression) => new ParenthesizedExpression(TokenFactory.tokenFromType(TokenType.OPEN_PAREN), expression, TokenFactory.tokenFromType(TokenType.CLOSE_PAREN));
577
578 static PartDirective partDirective(List<Annotation> metadata, String url) => n ew PartDirective(null, metadata, TokenFactory.tokenFromKeyword(Keyword.PART), st ring2(url), TokenFactory.tokenFromType(TokenType.SEMICOLON));
579
580 static PartDirective partDirective2(String url) => partDirective(new List<Anno tation>(), url);
581
582 static PartOfDirective partOfDirective(LibraryIdentifier libraryName) => partO fDirective2(new List<Annotation>(), libraryName);
583
584 static PartOfDirective partOfDirective2(List<Annotation> metadata, LibraryIden tifier libraryName) => new PartOfDirective(null, metadata, TokenFactory.tokenFro mKeyword(Keyword.PART), TokenFactory.tokenFromString("of"), libraryName, TokenFa ctory.tokenFromType(TokenType.SEMICOLON));
585
586 static DefaultFormalParameter positionalFormalParameter(NormalFormalParameter parameter, Expression expression) => new DefaultFormalParameter(parameter, Param eterKind.POSITIONAL, expression == null ? null : TokenFactory.tokenFromType(Toke nType.EQ), expression);
587
588 static PostfixExpression postfixExpression(Expression expression, TokenType op erator) => new PostfixExpression(expression, TokenFactory.tokenFromType(operator ));
589
590 static PrefixExpression prefixExpression(TokenType operator, Expression expres sion) => new PrefixExpression(TokenFactory.tokenFromType(operator), expression);
591
592 static PropertyAccess propertyAccess(Expression target, SimpleIdentifier prope rtyName) => new PropertyAccess(target, TokenFactory.tokenFromType(TokenType.PERI OD), propertyName);
593
594 static PropertyAccess propertyAccess2(Expression target, String propertyName) => new PropertyAccess(target, TokenFactory.tokenFromType(TokenType.PERIOD), iden tifier3(propertyName));
595
596 static RedirectingConstructorInvocation redirectingConstructorInvocation(List< Expression> arguments) => redirectingConstructorInvocation2(null, arguments);
597
598 static RedirectingConstructorInvocation redirectingConstructorInvocation2(Stri ng constructorName, List<Expression> arguments) => new RedirectingConstructorInv ocation(TokenFactory.tokenFromKeyword(Keyword.THIS), constructorName == null ? n ull : TokenFactory.tokenFromType(TokenType.PERIOD), constructorName == null ? nu ll : identifier3(constructorName), argumentList(arguments));
599
600 static RethrowExpression rethrowExpression() => new RethrowExpression(TokenFac tory.tokenFromKeyword(Keyword.RETHROW));
601
602 static ReturnStatement returnStatement() => returnStatement2(null);
603
604 static ReturnStatement returnStatement2(Expression expression) => new ReturnSt atement(TokenFactory.tokenFromKeyword(Keyword.RETURN), expression, TokenFactory. tokenFromType(TokenType.SEMICOLON));
605
606 static ScriptTag scriptTag(String scriptTag) => new ScriptTag(TokenFactory.tok enFromString(scriptTag));
607
608 static ShowCombinator showCombinator(List<SimpleIdentifier> identifiers) => ne w ShowCombinator(TokenFactory.tokenFromString("show"), list(identifiers));
609
610 static ShowCombinator showCombinator2(List<String> identifiers) {
611 List<SimpleIdentifier> identifierList = new List<SimpleIdentifier>();
612 for (String identifier in identifiers) {
613 identifierList.add(identifier3(identifier));
614 }
615 return new ShowCombinator(TokenFactory.tokenFromString("show"), identifierLi st);
616 }
617
618 static SimpleFormalParameter simpleFormalParameter(Keyword keyword, String par ameterName) => simpleFormalParameter2(keyword, null, parameterName);
619
620 static SimpleFormalParameter simpleFormalParameter2(Keyword keyword, TypeName type, String parameterName) => new SimpleFormalParameter(null, null, keyword == null ? null : TokenFactory.tokenFromKeyword(keyword), type, identifier3(paramete rName));
621
622 static SimpleFormalParameter simpleFormalParameter3(String parameterName) => s impleFormalParameter2(null, null, parameterName);
623
624 static SimpleFormalParameter simpleFormalParameter4(TypeName type, String para meterName) => simpleFormalParameter2(null, type, parameterName);
625
626 static StringInterpolation string(List<InterpolationElement> elements) => new StringInterpolation(list(elements));
627
628 static SimpleStringLiteral string2(String content) => new SimpleStringLiteral( TokenFactory.tokenFromString("'${content}'"), content);
629
630 static SuperConstructorInvocation superConstructorInvocation(List<Expression> arguments) => superConstructorInvocation2(null, arguments);
631
632 static SuperConstructorInvocation superConstructorInvocation2(String name, Lis t<Expression> arguments) => new SuperConstructorInvocation(TokenFactory.tokenFro mKeyword(Keyword.SUPER), name == null ? null : TokenFactory.tokenFromType(TokenT ype.PERIOD), name == null ? null : identifier3(name), argumentList(arguments));
633
634 static SuperExpression superExpression() => new SuperExpression(TokenFactory.t okenFromKeyword(Keyword.SUPER));
635
636 static SwitchCase switchCase(Expression expression, List<Statement> statements ) => switchCase2(new List<Label>(), expression, statements);
637
638 static SwitchCase switchCase2(List<Label> labels, Expression expression, List< Statement> statements) => new SwitchCase(labels, TokenFactory.tokenFromKeyword(K eyword.CASE), expression, TokenFactory.tokenFromType(TokenType.COLON), list(stat ements));
639
640 static SwitchDefault switchDefault(List<Label> labels, List<Statement> stateme nts) => new SwitchDefault(labels, TokenFactory.tokenFromKeyword(Keyword.DEFAULT) , TokenFactory.tokenFromType(TokenType.COLON), list(statements));
641
642 static SwitchDefault switchDefault2(List<Statement> statements) => switchDefau lt(new List<Label>(), statements);
643
644 static SwitchStatement switchStatement(Expression expression, List<SwitchMembe r> members) => new SwitchStatement(TokenFactory.tokenFromKeyword(Keyword.SWITCH) , TokenFactory.tokenFromType(TokenType.OPEN_PAREN), expression, TokenFactory.tok enFromType(TokenType.CLOSE_PAREN), TokenFactory.tokenFromType(TokenType.OPEN_CUR LY_BRACKET), list(members), TokenFactory.tokenFromType(TokenType.CLOSE_CURLY_BRA CKET));
645
646 static SymbolLiteral symbolLiteral(List<String> components) {
647 List<Token> identifierList = new List<Token>();
648 for (String component in components) {
649 identifierList.add(TokenFactory.tokenFromTypeAndString(TokenType.IDENTIFIE R, component));
650 }
651 return new SymbolLiteral(TokenFactory.tokenFromType(TokenType.HASH), new Lis t.from(identifierList));
652 }
653
654 static ThisExpression thisExpression() => new ThisExpression(TokenFactory.toke nFromKeyword(Keyword.THIS));
655
656 static ThrowExpression throwExpression() => throwExpression2(null);
657
658 static ThrowExpression throwExpression2(Expression expression) => new ThrowExp ression(TokenFactory.tokenFromKeyword(Keyword.THROW), expression);
659
660 static TopLevelVariableDeclaration topLevelVariableDeclaration(Keyword keyword , TypeName type, List<VariableDeclaration> variables) => new TopLevelVariableDec laration(null, null, variableDeclarationList(keyword, type, variables), TokenFac tory.tokenFromType(TokenType.SEMICOLON));
661
662 static TopLevelVariableDeclaration topLevelVariableDeclaration2(Keyword keywor d, List<VariableDeclaration> variables) => new TopLevelVariableDeclaration(null, null, variableDeclarationList(keyword, null, variables), TokenFactory.tokenFrom Type(TokenType.SEMICOLON));
663
664 static TryStatement tryStatement(Block body, Block finallyClause) => tryStatem ent3(body, new List<CatchClause>(), finallyClause);
665
666 static TryStatement tryStatement2(Block body, List<CatchClause> catchClauses) => tryStatement3(body, list(catchClauses), null);
667
668 static TryStatement tryStatement3(Block body, List<CatchClause> catchClauses, Block finallyClause) => new TryStatement(TokenFactory.tokenFromKeyword(Keyword.T RY), body, catchClauses, finallyClause == null ? null : TokenFactory.tokenFromKe yword(Keyword.FINALLY), finallyClause);
669
670 static FunctionTypeAlias typeAlias(TypeName returnType, String name, TypeParam eterList typeParameters, FormalParameterList parameters) => new FunctionTypeAlia s(null, null, TokenFactory.tokenFromKeyword(Keyword.TYPEDEF), returnType, identi fier3(name), typeParameters, parameters, TokenFactory.tokenFromType(TokenType.SE MICOLON));
671
672 static TypeArgumentList typeArgumentList(List<TypeName> typeNames) => new Type ArgumentList(TokenFactory.tokenFromType(TokenType.LT), list(typeNames), TokenFac tory.tokenFromType(TokenType.GT));
673
674 /**
675 * Create a type name whose name has been resolved to the given element and wh ose type has been
676 * resolved to the type of the given element.
677 *
678 * <b>Note:</b> This method does not correctly handle class elements that have type parameters.
679 *
680 * @param element the element defining the type represented by the type name
681 * @return the type name that was created
682 */
683 static TypeName typeName(ClassElement element, List<TypeName> arguments) {
684 SimpleIdentifier name = identifier3(element.name);
685 name.staticElement = element;
686 TypeName typeName = typeName3(name, arguments);
687 typeName.type = element.type;
688 return typeName;
689 }
690
691 static TypeName typeName3(Identifier name, List<TypeName> arguments) {
692 if (arguments.length == 0) {
693 return new TypeName(name, null);
694 }
695 return new TypeName(name, typeArgumentList(arguments));
696 }
697
698 static TypeName typeName4(String name, List<TypeName> arguments) {
699 if (arguments.length == 0) {
700 return new TypeName(identifier3(name), null);
701 }
702 return new TypeName(identifier3(name), typeArgumentList(arguments));
703 }
704
705 static TypeParameter typeParameter(String name) => new TypeParameter(null, nul l, identifier3(name), null, null);
706
707 static TypeParameter typeParameter2(String name, TypeName bound) => new TypePa rameter(null, null, identifier3(name), TokenFactory.tokenFromKeyword(Keyword.EXT ENDS), bound);
708
709 static TypeParameterList typeParameterList(List<String> typeNames) {
710 List<TypeParameter> typeParameters = new List<TypeParameter>();
711 for (String typeName in typeNames) {
712 typeParameters.add(typeParameter(typeName));
713 }
714 return new TypeParameterList(TokenFactory.tokenFromType(TokenType.LT), typeP arameters, TokenFactory.tokenFromType(TokenType.GT));
715 }
716
717 static VariableDeclaration variableDeclaration(String name) => new VariableDec laration(null, null, identifier3(name), null, null);
718
719 static VariableDeclaration variableDeclaration2(String name, Expression initia lizer) => new VariableDeclaration(null, null, identifier3(name), TokenFactory.to kenFromType(TokenType.EQ), initializer);
720
721 static VariableDeclarationList variableDeclarationList(Keyword keyword, TypeNa me type, List<VariableDeclaration> variables) => new VariableDeclarationList(nul l, null, keyword == null ? null : TokenFactory.tokenFromKeyword(keyword), type, list(variables));
722
723 static VariableDeclarationList variableDeclarationList2(Keyword keyword, List< VariableDeclaration> variables) => variableDeclarationList(keyword, null, variab les);
724
725 static VariableDeclarationStatement variableDeclarationStatement(Keyword keywo rd, TypeName type, List<VariableDeclaration> variables) => new VariableDeclarati onStatement(variableDeclarationList(keyword, type, variables), TokenFactory.toke nFromType(TokenType.SEMICOLON));
726
727 static VariableDeclarationStatement variableDeclarationStatement2(Keyword keyw ord, List<VariableDeclaration> variables) => variableDeclarationStatement(keywor d, null, variables);
728
729 static WhileStatement whileStatement(Expression condition, Statement body) => new WhileStatement(TokenFactory.tokenFromKeyword(Keyword.WHILE), TokenFactory.to kenFromType(TokenType.OPEN_PAREN), condition, TokenFactory.tokenFromType(TokenTy pe.CLOSE_PAREN), body);
730
731 static WithClause withClause(List<TypeName> types) => new WithClause(TokenFact ory.tokenFromKeyword(Keyword.WITH), list(types));
732 }
733
734 class SimpleIdentifierTest extends ParserTestCase { 23 class SimpleIdentifierTest extends ParserTestCase {
735 void test_inDeclarationContext_argumentDefinition() { 24 void test_inDeclarationContext_argumentDefinition() {
736 SimpleIdentifier identifier = AstFactory.argumentDefinitionTest("p").identif ier; 25 SimpleIdentifier identifier = AstFactory.argumentDefinitionTest("p").identif ier;
737 JUnitTestCase.assertFalse(identifier.inDeclarationContext()); 26 JUnitTestCase.assertFalse(identifier.inDeclarationContext());
738 } 27 }
739 28
740 void test_inDeclarationContext_catch_exception() { 29 void test_inDeclarationContext_catch_exception() {
741 SimpleIdentifier identifier = AstFactory.catchClause("e", []).exceptionParam eter; 30 SimpleIdentifier identifier = AstFactory.catchClause("e", []).exceptionParam eter;
742 JUnitTestCase.assertTrue(identifier.inDeclarationContext()); 31 JUnitTestCase.assertTrue(identifier.inDeclarationContext());
743 } 32 }
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 static const List<WrapperKind> values = const [ 347 static const List<WrapperKind> values = const [
1059 PREFIXED_LEFT, 348 PREFIXED_LEFT,
1060 PREFIXED_RIGHT, 349 PREFIXED_RIGHT,
1061 PROPERTY_LEFT, 350 PROPERTY_LEFT,
1062 PROPERTY_RIGHT, 351 PROPERTY_RIGHT,
1063 NONE]; 352 NONE];
1064 353
1065 const WrapperKind(String name, int ordinal) : super(name, ordinal); 354 const WrapperKind(String name, int ordinal) : super(name, ordinal);
1066 } 355 }
1067 356
1068 class BreadthFirstVisitorTest extends ParserTestCase {
1069 void testIt() {
1070 String source = EngineTestCase.createSource([
1071 "class A {",
1072 " bool get g => true;",
1073 "}",
1074 "class B {",
1075 " int f() {",
1076 " num q() {",
1077 " return 3;",
1078 " }",
1079 " return q() + 4;",
1080 " }",
1081 "}",
1082 "A f(var p) {",
1083 " if ((p as A).g) {",
1084 " return p;",
1085 " } else {",
1086 " return null;",
1087 " }",
1088 "}"]);
1089 CompilationUnit unit = ParserTestCase.parseCompilationUnit(source, []);
1090 List<AstNode> nodes = new List<AstNode>();
1091 BreadthFirstVisitor<Object> visitor = new BreadthFirstVisitor_BreadthFirstVi sitorTest_testIt(nodes);
1092 visitor.visitAllNodes(unit);
1093 EngineTestCase.assertSizeOfList(59, nodes);
1094 EngineTestCase.assertInstanceOf((obj) => obj is CompilationUnit, Compilation Unit, nodes[0]);
1095 EngineTestCase.assertInstanceOf((obj) => obj is ClassDeclaration, ClassDecla ration, nodes[2]);
1096 EngineTestCase.assertInstanceOf((obj) => obj is FunctionDeclaration, Functio nDeclaration, nodes[3]);
1097 EngineTestCase.assertInstanceOf((obj) => obj is FunctionDeclarationStatement , FunctionDeclarationStatement, nodes[27]);
1098 EngineTestCase.assertInstanceOf((obj) => obj is IntegerLiteral, IntegerLiter al, nodes[58]);
1099 }
1100
1101 static dartSuite() {
1102 _ut.group('BreadthFirstVisitorTest', () {
1103 _ut.test('testIt', () {
1104 final __test = new BreadthFirstVisitorTest();
1105 runJUnitTest(__test, __test.testIt);
1106 });
1107 });
1108 }
1109 }
1110
1111 class BreadthFirstVisitor_BreadthFirstVisitorTest_testIt extends BreadthFirstVis itor<Object> {
1112 List<AstNode> nodes;
1113
1114 BreadthFirstVisitor_BreadthFirstVisitorTest_testIt(this.nodes) : super();
1115
1116 @override
1117 Object visitNode(AstNode node) {
1118 nodes.add(node);
1119 return super.visitNode(node);
1120 }
1121 }
1122
1123 class NodeListTest extends EngineTestCase {
1124 void test_add() {
1125 AstNode parent = AstFactory.argumentList([]);
1126 AstNode firstNode = AstFactory.booleanLiteral(true);
1127 AstNode secondNode = AstFactory.booleanLiteral(false);
1128 NodeList<AstNode> list = new NodeList<AstNode>(parent);
1129 list.insert(0, secondNode);
1130 list.insert(0, firstNode);
1131 EngineTestCase.assertSizeOfList(2, list);
1132 JUnitTestCase.assertSame(firstNode, list[0]);
1133 JUnitTestCase.assertSame(secondNode, list[1]);
1134 JUnitTestCase.assertSame(parent, firstNode.parent);
1135 JUnitTestCase.assertSame(parent, secondNode.parent);
1136 AstNode thirdNode = AstFactory.booleanLiteral(false);
1137 list.insert(1, thirdNode);
1138 EngineTestCase.assertSizeOfList(3, list);
1139 JUnitTestCase.assertSame(firstNode, list[0]);
1140 JUnitTestCase.assertSame(thirdNode, list[1]);
1141 JUnitTestCase.assertSame(secondNode, list[2]);
1142 JUnitTestCase.assertSame(parent, firstNode.parent);
1143 JUnitTestCase.assertSame(parent, secondNode.parent);
1144 JUnitTestCase.assertSame(parent, thirdNode.parent);
1145 }
1146
1147 void test_add_negative() {
1148 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
1149 try {
1150 list.insert(-1, AstFactory.booleanLiteral(true));
1151 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
1152 } on RangeError catch (exception) {
1153 }
1154 }
1155
1156 void test_add_tooBig() {
1157 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
1158 try {
1159 list.insert(1, AstFactory.booleanLiteral(true));
1160 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
1161 } on RangeError catch (exception) {
1162 }
1163 }
1164
1165 void test_addAll() {
1166 AstNode parent = AstFactory.argumentList([]);
1167 List<AstNode> firstNodes = new List<AstNode>();
1168 AstNode firstNode = AstFactory.booleanLiteral(true);
1169 AstNode secondNode = AstFactory.booleanLiteral(false);
1170 firstNodes.add(firstNode);
1171 firstNodes.add(secondNode);
1172 NodeList<AstNode> list = new NodeList<AstNode>(parent);
1173 list.addAll(firstNodes);
1174 EngineTestCase.assertSizeOfList(2, list);
1175 JUnitTestCase.assertSame(firstNode, list[0]);
1176 JUnitTestCase.assertSame(secondNode, list[1]);
1177 JUnitTestCase.assertSame(parent, firstNode.parent);
1178 JUnitTestCase.assertSame(parent, secondNode.parent);
1179 List<AstNode> secondNodes = new List<AstNode>();
1180 AstNode thirdNode = AstFactory.booleanLiteral(true);
1181 AstNode fourthNode = AstFactory.booleanLiteral(false);
1182 secondNodes.add(thirdNode);
1183 secondNodes.add(fourthNode);
1184 list.addAll(secondNodes);
1185 EngineTestCase.assertSizeOfList(4, list);
1186 JUnitTestCase.assertSame(firstNode, list[0]);
1187 JUnitTestCase.assertSame(secondNode, list[1]);
1188 JUnitTestCase.assertSame(thirdNode, list[2]);
1189 JUnitTestCase.assertSame(fourthNode, list[3]);
1190 JUnitTestCase.assertSame(parent, firstNode.parent);
1191 JUnitTestCase.assertSame(parent, secondNode.parent);
1192 JUnitTestCase.assertSame(parent, thirdNode.parent);
1193 JUnitTestCase.assertSame(parent, fourthNode.parent);
1194 }
1195
1196 void test_create() {
1197 AstNode owner = AstFactory.argumentList([]);
1198 NodeList<AstNode> list = NodeList.create(owner);
1199 JUnitTestCase.assertNotNull(list);
1200 EngineTestCase.assertSizeOfList(0, list);
1201 JUnitTestCase.assertSame(owner, list.owner);
1202 }
1203
1204 void test_creation() {
1205 AstNode owner = AstFactory.argumentList([]);
1206 NodeList<AstNode> list = new NodeList<AstNode>(owner);
1207 JUnitTestCase.assertNotNull(list);
1208 EngineTestCase.assertSizeOfList(0, list);
1209 JUnitTestCase.assertSame(owner, list.owner);
1210 }
1211
1212 void test_get_negative() {
1213 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
1214 try {
1215 list[-1];
1216 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
1217 } on RangeError catch (exception) {
1218 }
1219 }
1220
1221 void test_get_tooBig() {
1222 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
1223 try {
1224 list[1];
1225 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
1226 } on RangeError catch (exception) {
1227 }
1228 }
1229
1230 void test_getBeginToken_empty() {
1231 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
1232 JUnitTestCase.assertNull(list.beginToken);
1233 }
1234
1235 void test_getBeginToken_nonEmpty() {
1236 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
1237 AstNode node = AstFactory.parenthesizedExpression(AstFactory.booleanLiteral( true));
1238 list.add(node);
1239 JUnitTestCase.assertSame(node.beginToken, list.beginToken);
1240 }
1241
1242 void test_getEndToken_empty() {
1243 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
1244 JUnitTestCase.assertNull(list.endToken);
1245 }
1246
1247 void test_getEndToken_nonEmpty() {
1248 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
1249 AstNode node = AstFactory.parenthesizedExpression(AstFactory.booleanLiteral( true));
1250 list.add(node);
1251 JUnitTestCase.assertSame(node.endToken, list.endToken);
1252 }
1253
1254 void test_indexOf() {
1255 List<AstNode> nodes = new List<AstNode>();
1256 AstNode firstNode = AstFactory.booleanLiteral(true);
1257 AstNode secondNode = AstFactory.booleanLiteral(false);
1258 AstNode thirdNode = AstFactory.booleanLiteral(true);
1259 AstNode fourthNode = AstFactory.booleanLiteral(false);
1260 nodes.add(firstNode);
1261 nodes.add(secondNode);
1262 nodes.add(thirdNode);
1263 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
1264 list.addAll(nodes);
1265 EngineTestCase.assertSizeOfList(3, list);
1266 JUnitTestCase.assertEquals(0, list.indexOf(firstNode));
1267 JUnitTestCase.assertEquals(1, list.indexOf(secondNode));
1268 JUnitTestCase.assertEquals(2, list.indexOf(thirdNode));
1269 JUnitTestCase.assertEquals(-1, list.indexOf(fourthNode));
1270 JUnitTestCase.assertEquals(-1, list.indexOf(null));
1271 }
1272
1273 void test_remove() {
1274 List<AstNode> nodes = new List<AstNode>();
1275 AstNode firstNode = AstFactory.booleanLiteral(true);
1276 AstNode secondNode = AstFactory.booleanLiteral(false);
1277 AstNode thirdNode = AstFactory.booleanLiteral(true);
1278 nodes.add(firstNode);
1279 nodes.add(secondNode);
1280 nodes.add(thirdNode);
1281 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
1282 list.addAll(nodes);
1283 EngineTestCase.assertSizeOfList(3, list);
1284 JUnitTestCase.assertSame(secondNode, list.removeAt(1));
1285 EngineTestCase.assertSizeOfList(2, list);
1286 JUnitTestCase.assertSame(firstNode, list[0]);
1287 JUnitTestCase.assertSame(thirdNode, list[1]);
1288 }
1289
1290 void test_remove_negative() {
1291 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
1292 try {
1293 list.removeAt(-1);
1294 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
1295 } on RangeError catch (exception) {
1296 }
1297 }
1298
1299 void test_remove_tooBig() {
1300 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
1301 try {
1302 list.removeAt(1);
1303 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
1304 } on RangeError catch (exception) {
1305 }
1306 }
1307
1308 void test_set() {
1309 List<AstNode> nodes = new List<AstNode>();
1310 AstNode firstNode = AstFactory.booleanLiteral(true);
1311 AstNode secondNode = AstFactory.booleanLiteral(false);
1312 AstNode thirdNode = AstFactory.booleanLiteral(true);
1313 nodes.add(firstNode);
1314 nodes.add(secondNode);
1315 nodes.add(thirdNode);
1316 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
1317 list.addAll(nodes);
1318 EngineTestCase.assertSizeOfList(3, list);
1319 AstNode fourthNode = AstFactory.integer(0);
1320 JUnitTestCase.assertSame(secondNode, javaListSet(list, 1, fourthNode));
1321 EngineTestCase.assertSizeOfList(3, list);
1322 JUnitTestCase.assertSame(firstNode, list[0]);
1323 JUnitTestCase.assertSame(fourthNode, list[1]);
1324 JUnitTestCase.assertSame(thirdNode, list[2]);
1325 }
1326
1327 void test_set_negative() {
1328 AstNode node = AstFactory.booleanLiteral(true);
1329 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
1330 try {
1331 javaListSet(list, -1, node);
1332 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
1333 } on RangeError catch (exception) {
1334 }
1335 }
1336
1337 void test_set_tooBig() {
1338 AstNode node = AstFactory.booleanLiteral(true);
1339 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
1340 try {
1341 javaListSet(list, 1, node);
1342 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
1343 } on RangeError catch (exception) {
1344 }
1345 }
1346
1347 static dartSuite() {
1348 _ut.group('NodeListTest', () {
1349 _ut.test('test_add', () {
1350 final __test = new NodeListTest();
1351 runJUnitTest(__test, __test.test_add);
1352 });
1353 _ut.test('test_addAll', () {
1354 final __test = new NodeListTest();
1355 runJUnitTest(__test, __test.test_addAll);
1356 });
1357 _ut.test('test_add_negative', () {
1358 final __test = new NodeListTest();
1359 runJUnitTest(__test, __test.test_add_negative);
1360 });
1361 _ut.test('test_add_tooBig', () {
1362 final __test = new NodeListTest();
1363 runJUnitTest(__test, __test.test_add_tooBig);
1364 });
1365 _ut.test('test_create', () {
1366 final __test = new NodeListTest();
1367 runJUnitTest(__test, __test.test_create);
1368 });
1369 _ut.test('test_creation', () {
1370 final __test = new NodeListTest();
1371 runJUnitTest(__test, __test.test_creation);
1372 });
1373 _ut.test('test_getBeginToken_empty', () {
1374 final __test = new NodeListTest();
1375 runJUnitTest(__test, __test.test_getBeginToken_empty);
1376 });
1377 _ut.test('test_getBeginToken_nonEmpty', () {
1378 final __test = new NodeListTest();
1379 runJUnitTest(__test, __test.test_getBeginToken_nonEmpty);
1380 });
1381 _ut.test('test_getEndToken_empty', () {
1382 final __test = new NodeListTest();
1383 runJUnitTest(__test, __test.test_getEndToken_empty);
1384 });
1385 _ut.test('test_getEndToken_nonEmpty', () {
1386 final __test = new NodeListTest();
1387 runJUnitTest(__test, __test.test_getEndToken_nonEmpty);
1388 });
1389 _ut.test('test_get_negative', () {
1390 final __test = new NodeListTest();
1391 runJUnitTest(__test, __test.test_get_negative);
1392 });
1393 _ut.test('test_get_tooBig', () {
1394 final __test = new NodeListTest();
1395 runJUnitTest(__test, __test.test_get_tooBig);
1396 });
1397 _ut.test('test_indexOf', () {
1398 final __test = new NodeListTest();
1399 runJUnitTest(__test, __test.test_indexOf);
1400 });
1401 _ut.test('test_remove', () {
1402 final __test = new NodeListTest();
1403 runJUnitTest(__test, __test.test_remove);
1404 });
1405 _ut.test('test_remove_negative', () {
1406 final __test = new NodeListTest();
1407 runJUnitTest(__test, __test.test_remove_negative);
1408 });
1409 _ut.test('test_remove_tooBig', () {
1410 final __test = new NodeListTest();
1411 runJUnitTest(__test, __test.test_remove_tooBig);
1412 });
1413 _ut.test('test_set', () {
1414 final __test = new NodeListTest();
1415 runJUnitTest(__test, __test.test_set);
1416 });
1417 _ut.test('test_set_negative', () {
1418 final __test = new NodeListTest();
1419 runJUnitTest(__test, __test.test_set_negative);
1420 });
1421 _ut.test('test_set_tooBig', () {
1422 final __test = new NodeListTest();
1423 runJUnitTest(__test, __test.test_set_tooBig);
1424 });
1425 });
1426 }
1427 }
1428
1429 class ClassTypeAliasTest extends ParserTestCase {
1430 void test_isAbstract() {
1431 JUnitTestCase.assertFalse(AstFactory.classTypeAlias("A", null, null, null, n ull, null).isAbstract);
1432 JUnitTestCase.assertTrue(AstFactory.classTypeAlias("B", null, Keyword.ABSTRA CT, null, null, null).isAbstract);
1433 }
1434
1435 static dartSuite() {
1436 _ut.group('ClassTypeAliasTest', () {
1437 _ut.test('test_isAbstract', () {
1438 final __test = new ClassTypeAliasTest();
1439 runJUnitTest(__test, __test.test_isAbstract);
1440 });
1441 });
1442 }
1443 }
1444
1445 class ConstantEvaluatorTest extends ParserTestCase {
1446 void fail_constructor() {
1447 Object value = _getConstantValue("?");
1448 JUnitTestCase.assertEquals(null, value);
1449 }
1450
1451 void fail_identifier_class() {
1452 Object value = _getConstantValue("?");
1453 JUnitTestCase.assertEquals(null, value);
1454 }
1455
1456 void fail_identifier_function() {
1457 Object value = _getConstantValue("?");
1458 JUnitTestCase.assertEquals(null, value);
1459 }
1460
1461 void fail_identifier_static() {
1462 Object value = _getConstantValue("?");
1463 JUnitTestCase.assertEquals(null, value);
1464 }
1465
1466 void fail_identifier_staticMethod() {
1467 Object value = _getConstantValue("?");
1468 JUnitTestCase.assertEquals(null, value);
1469 }
1470
1471 void fail_identifier_topLevel() {
1472 Object value = _getConstantValue("?");
1473 JUnitTestCase.assertEquals(null, value);
1474 }
1475
1476 void fail_identifier_typeParameter() {
1477 Object value = _getConstantValue("?");
1478 JUnitTestCase.assertEquals(null, value);
1479 }
1480
1481 void test_binary_bitAnd() {
1482 Object value = _getConstantValue("74 & 42");
1483 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
1484 JUnitTestCase.assertEquals(74 & 42, value as int);
1485 }
1486
1487 void test_binary_bitOr() {
1488 Object value = _getConstantValue("74 | 42");
1489 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
1490 JUnitTestCase.assertEquals(74 | 42, value as int);
1491 }
1492
1493 void test_binary_bitXor() {
1494 Object value = _getConstantValue("74 ^ 42");
1495 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
1496 JUnitTestCase.assertEquals(74 ^ 42, value as int);
1497 }
1498
1499 void test_binary_divide_double() {
1500 Object value = _getConstantValue("3.2 / 2.3");
1501 EngineTestCase.assertInstanceOf((obj) => obj is double, double, value);
1502 JUnitTestCase.assertEquals(3.2 / 2.3, value as double);
1503 }
1504
1505 void test_binary_divide_integer() {
1506 Object value = _getConstantValue("3 / 2");
1507 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
1508 JUnitTestCase.assertEquals(1, value as int);
1509 }
1510
1511 void test_binary_equal_boolean() {
1512 Object value = _getConstantValue("true == false");
1513 JUnitTestCase.assertEquals(false, value);
1514 }
1515
1516 void test_binary_equal_integer() {
1517 Object value = _getConstantValue("2 == 3");
1518 JUnitTestCase.assertEquals(false, value);
1519 }
1520
1521 void test_binary_equal_invalidLeft() {
1522 Object value = _getConstantValue("a == 3");
1523 JUnitTestCase.assertEquals(ConstantEvaluator.NOT_A_CONSTANT, value);
1524 }
1525
1526 void test_binary_equal_invalidRight() {
1527 Object value = _getConstantValue("2 == a");
1528 JUnitTestCase.assertEquals(ConstantEvaluator.NOT_A_CONSTANT, value);
1529 }
1530
1531 void test_binary_equal_string() {
1532 Object value = _getConstantValue("'a' == 'b'");
1533 JUnitTestCase.assertEquals(false, value);
1534 }
1535
1536 void test_binary_greaterThan() {
1537 Object value = _getConstantValue("2 > 3");
1538 JUnitTestCase.assertEquals(false, value);
1539 }
1540
1541 void test_binary_greaterThanOrEqual() {
1542 Object value = _getConstantValue("2 >= 3");
1543 JUnitTestCase.assertEquals(false, value);
1544 }
1545
1546 void test_binary_leftShift() {
1547 Object value = _getConstantValue("16 << 2");
1548 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
1549 JUnitTestCase.assertEquals(64, value as int);
1550 }
1551
1552 void test_binary_lessThan() {
1553 Object value = _getConstantValue("2 < 3");
1554 JUnitTestCase.assertEquals(true, value);
1555 }
1556
1557 void test_binary_lessThanOrEqual() {
1558 Object value = _getConstantValue("2 <= 3");
1559 JUnitTestCase.assertEquals(true, value);
1560 }
1561
1562 void test_binary_logicalAnd() {
1563 Object value = _getConstantValue("true && false");
1564 JUnitTestCase.assertEquals(false, value);
1565 }
1566
1567 void test_binary_logicalOr() {
1568 Object value = _getConstantValue("true || false");
1569 JUnitTestCase.assertEquals(true, value);
1570 }
1571
1572 void test_binary_minus_double() {
1573 Object value = _getConstantValue("3.2 - 2.3");
1574 EngineTestCase.assertInstanceOf((obj) => obj is double, double, value);
1575 JUnitTestCase.assertEquals(3.2 - 2.3, value as double);
1576 }
1577
1578 void test_binary_minus_integer() {
1579 Object value = _getConstantValue("3 - 2");
1580 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
1581 JUnitTestCase.assertEquals(1, value as int);
1582 }
1583
1584 void test_binary_notEqual_boolean() {
1585 Object value = _getConstantValue("true != false");
1586 JUnitTestCase.assertEquals(true, value);
1587 }
1588
1589 void test_binary_notEqual_integer() {
1590 Object value = _getConstantValue("2 != 3");
1591 JUnitTestCase.assertEquals(true, value);
1592 }
1593
1594 void test_binary_notEqual_invalidLeft() {
1595 Object value = _getConstantValue("a != 3");
1596 JUnitTestCase.assertEquals(ConstantEvaluator.NOT_A_CONSTANT, value);
1597 }
1598
1599 void test_binary_notEqual_invalidRight() {
1600 Object value = _getConstantValue("2 != a");
1601 JUnitTestCase.assertEquals(ConstantEvaluator.NOT_A_CONSTANT, value);
1602 }
1603
1604 void test_binary_notEqual_string() {
1605 Object value = _getConstantValue("'a' != 'b'");
1606 JUnitTestCase.assertEquals(true, value);
1607 }
1608
1609 void test_binary_plus_double() {
1610 Object value = _getConstantValue("2.3 + 3.2");
1611 EngineTestCase.assertInstanceOf((obj) => obj is double, double, value);
1612 JUnitTestCase.assertEquals(2.3 + 3.2, value as double);
1613 }
1614
1615 void test_binary_plus_integer() {
1616 Object value = _getConstantValue("2 + 3");
1617 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
1618 JUnitTestCase.assertEquals(5, value as int);
1619 }
1620
1621 void test_binary_remainder_double() {
1622 Object value = _getConstantValue("3.2 % 2.3");
1623 EngineTestCase.assertInstanceOf((obj) => obj is double, double, value);
1624 JUnitTestCase.assertEquals(3.2 % 2.3, value as double);
1625 }
1626
1627 void test_binary_remainder_integer() {
1628 Object value = _getConstantValue("8 % 3");
1629 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
1630 JUnitTestCase.assertEquals(2, value as int);
1631 }
1632
1633 void test_binary_rightShift() {
1634 Object value = _getConstantValue("64 >> 2");
1635 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
1636 JUnitTestCase.assertEquals(16, value as int);
1637 }
1638
1639 void test_binary_times_double() {
1640 Object value = _getConstantValue("2.3 * 3.2");
1641 EngineTestCase.assertInstanceOf((obj) => obj is double, double, value);
1642 JUnitTestCase.assertEquals(2.3 * 3.2, value as double);
1643 }
1644
1645 void test_binary_times_integer() {
1646 Object value = _getConstantValue("2 * 3");
1647 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
1648 JUnitTestCase.assertEquals(6, value as int);
1649 }
1650
1651 void test_binary_truncatingDivide_double() {
1652 Object value = _getConstantValue("3.2 ~/ 2.3");
1653 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
1654 JUnitTestCase.assertEquals(1, value as int);
1655 }
1656
1657 void test_binary_truncatingDivide_integer() {
1658 Object value = _getConstantValue("10 ~/ 3");
1659 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
1660 JUnitTestCase.assertEquals(3, value as int);
1661 }
1662
1663 void test_literal_boolean_false() {
1664 Object value = _getConstantValue("false");
1665 JUnitTestCase.assertEquals(false, value);
1666 }
1667
1668 void test_literal_boolean_true() {
1669 Object value = _getConstantValue("true");
1670 JUnitTestCase.assertEquals(true, value);
1671 }
1672
1673 void test_literal_list() {
1674 Object value = _getConstantValue("['a', 'b', 'c']");
1675 EngineTestCase.assertInstanceOf((obj) => obj is List, List, value);
1676 List list = value as List;
1677 JUnitTestCase.assertEquals(3, list.length);
1678 JUnitTestCase.assertEquals("a", list[0]);
1679 JUnitTestCase.assertEquals("b", list[1]);
1680 JUnitTestCase.assertEquals("c", list[2]);
1681 }
1682
1683 void test_literal_map() {
1684 Object value = _getConstantValue("{'a' : 'm', 'b' : 'n', 'c' : 'o'}");
1685 EngineTestCase.assertInstanceOf((obj) => obj is Map, Map, value);
1686 Map map = value as Map;
1687 JUnitTestCase.assertEquals(3, map.length);
1688 JUnitTestCase.assertEquals("m", map["a"]);
1689 JUnitTestCase.assertEquals("n", map["b"]);
1690 JUnitTestCase.assertEquals("o", map["c"]);
1691 }
1692
1693 void test_literal_null() {
1694 Object value = _getConstantValue("null");
1695 JUnitTestCase.assertEquals(null, value);
1696 }
1697
1698 void test_literal_number_double() {
1699 Object value = _getConstantValue("3.45");
1700 EngineTestCase.assertInstanceOf((obj) => obj is double, double, value);
1701 JUnitTestCase.assertEquals(3.45, value as double);
1702 }
1703
1704 void test_literal_number_integer() {
1705 Object value = _getConstantValue("42");
1706 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
1707 JUnitTestCase.assertEquals(42, value as int);
1708 }
1709
1710 void test_literal_string_adjacent() {
1711 Object value = _getConstantValue("'abc' 'def'");
1712 JUnitTestCase.assertEquals("abcdef", value);
1713 }
1714
1715 void test_literal_string_interpolation_invalid() {
1716 Object value = _getConstantValue("'a\${f()}c'");
1717 JUnitTestCase.assertEquals(ConstantEvaluator.NOT_A_CONSTANT, value);
1718 }
1719
1720 void test_literal_string_interpolation_valid() {
1721 Object value = _getConstantValue("'a\${3}c'");
1722 JUnitTestCase.assertEquals("a3c", value);
1723 }
1724
1725 void test_literal_string_simple() {
1726 Object value = _getConstantValue("'abc'");
1727 JUnitTestCase.assertEquals("abc", value);
1728 }
1729
1730 void test_parenthesizedExpression() {
1731 Object value = _getConstantValue("('a')");
1732 JUnitTestCase.assertEquals("a", value);
1733 }
1734
1735 void test_unary_bitNot() {
1736 Object value = _getConstantValue("~42");
1737 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
1738 JUnitTestCase.assertEquals(~42, value as int);
1739 }
1740
1741 void test_unary_logicalNot() {
1742 Object value = _getConstantValue("!true");
1743 JUnitTestCase.assertEquals(false, value);
1744 }
1745
1746 void test_unary_negated_double() {
1747 Object value = _getConstantValue("-42.3");
1748 EngineTestCase.assertInstanceOf((obj) => obj is double, double, value);
1749 JUnitTestCase.assertEquals(-42.3, value as double);
1750 }
1751
1752 void test_unary_negated_integer() {
1753 Object value = _getConstantValue("-42");
1754 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
1755 JUnitTestCase.assertEquals(-42, value as int);
1756 }
1757
1758 Object _getConstantValue(String source) => ParserTestCase.parseExpression(sour ce, []).accept(new ConstantEvaluator());
1759
1760 static dartSuite() {
1761 _ut.group('ConstantEvaluatorTest', () {
1762 _ut.test('test_binary_bitAnd', () {
1763 final __test = new ConstantEvaluatorTest();
1764 runJUnitTest(__test, __test.test_binary_bitAnd);
1765 });
1766 _ut.test('test_binary_bitOr', () {
1767 final __test = new ConstantEvaluatorTest();
1768 runJUnitTest(__test, __test.test_binary_bitOr);
1769 });
1770 _ut.test('test_binary_bitXor', () {
1771 final __test = new ConstantEvaluatorTest();
1772 runJUnitTest(__test, __test.test_binary_bitXor);
1773 });
1774 _ut.test('test_binary_divide_double', () {
1775 final __test = new ConstantEvaluatorTest();
1776 runJUnitTest(__test, __test.test_binary_divide_double);
1777 });
1778 _ut.test('test_binary_divide_integer', () {
1779 final __test = new ConstantEvaluatorTest();
1780 runJUnitTest(__test, __test.test_binary_divide_integer);
1781 });
1782 _ut.test('test_binary_equal_boolean', () {
1783 final __test = new ConstantEvaluatorTest();
1784 runJUnitTest(__test, __test.test_binary_equal_boolean);
1785 });
1786 _ut.test('test_binary_equal_integer', () {
1787 final __test = new ConstantEvaluatorTest();
1788 runJUnitTest(__test, __test.test_binary_equal_integer);
1789 });
1790 _ut.test('test_binary_equal_invalidLeft', () {
1791 final __test = new ConstantEvaluatorTest();
1792 runJUnitTest(__test, __test.test_binary_equal_invalidLeft);
1793 });
1794 _ut.test('test_binary_equal_invalidRight', () {
1795 final __test = new ConstantEvaluatorTest();
1796 runJUnitTest(__test, __test.test_binary_equal_invalidRight);
1797 });
1798 _ut.test('test_binary_equal_string', () {
1799 final __test = new ConstantEvaluatorTest();
1800 runJUnitTest(__test, __test.test_binary_equal_string);
1801 });
1802 _ut.test('test_binary_greaterThan', () {
1803 final __test = new ConstantEvaluatorTest();
1804 runJUnitTest(__test, __test.test_binary_greaterThan);
1805 });
1806 _ut.test('test_binary_greaterThanOrEqual', () {
1807 final __test = new ConstantEvaluatorTest();
1808 runJUnitTest(__test, __test.test_binary_greaterThanOrEqual);
1809 });
1810 _ut.test('test_binary_leftShift', () {
1811 final __test = new ConstantEvaluatorTest();
1812 runJUnitTest(__test, __test.test_binary_leftShift);
1813 });
1814 _ut.test('test_binary_lessThan', () {
1815 final __test = new ConstantEvaluatorTest();
1816 runJUnitTest(__test, __test.test_binary_lessThan);
1817 });
1818 _ut.test('test_binary_lessThanOrEqual', () {
1819 final __test = new ConstantEvaluatorTest();
1820 runJUnitTest(__test, __test.test_binary_lessThanOrEqual);
1821 });
1822 _ut.test('test_binary_logicalAnd', () {
1823 final __test = new ConstantEvaluatorTest();
1824 runJUnitTest(__test, __test.test_binary_logicalAnd);
1825 });
1826 _ut.test('test_binary_logicalOr', () {
1827 final __test = new ConstantEvaluatorTest();
1828 runJUnitTest(__test, __test.test_binary_logicalOr);
1829 });
1830 _ut.test('test_binary_minus_double', () {
1831 final __test = new ConstantEvaluatorTest();
1832 runJUnitTest(__test, __test.test_binary_minus_double);
1833 });
1834 _ut.test('test_binary_minus_integer', () {
1835 final __test = new ConstantEvaluatorTest();
1836 runJUnitTest(__test, __test.test_binary_minus_integer);
1837 });
1838 _ut.test('test_binary_notEqual_boolean', () {
1839 final __test = new ConstantEvaluatorTest();
1840 runJUnitTest(__test, __test.test_binary_notEqual_boolean);
1841 });
1842 _ut.test('test_binary_notEqual_integer', () {
1843 final __test = new ConstantEvaluatorTest();
1844 runJUnitTest(__test, __test.test_binary_notEqual_integer);
1845 });
1846 _ut.test('test_binary_notEqual_invalidLeft', () {
1847 final __test = new ConstantEvaluatorTest();
1848 runJUnitTest(__test, __test.test_binary_notEqual_invalidLeft);
1849 });
1850 _ut.test('test_binary_notEqual_invalidRight', () {
1851 final __test = new ConstantEvaluatorTest();
1852 runJUnitTest(__test, __test.test_binary_notEqual_invalidRight);
1853 });
1854 _ut.test('test_binary_notEqual_string', () {
1855 final __test = new ConstantEvaluatorTest();
1856 runJUnitTest(__test, __test.test_binary_notEqual_string);
1857 });
1858 _ut.test('test_binary_plus_double', () {
1859 final __test = new ConstantEvaluatorTest();
1860 runJUnitTest(__test, __test.test_binary_plus_double);
1861 });
1862 _ut.test('test_binary_plus_integer', () {
1863 final __test = new ConstantEvaluatorTest();
1864 runJUnitTest(__test, __test.test_binary_plus_integer);
1865 });
1866 _ut.test('test_binary_remainder_double', () {
1867 final __test = new ConstantEvaluatorTest();
1868 runJUnitTest(__test, __test.test_binary_remainder_double);
1869 });
1870 _ut.test('test_binary_remainder_integer', () {
1871 final __test = new ConstantEvaluatorTest();
1872 runJUnitTest(__test, __test.test_binary_remainder_integer);
1873 });
1874 _ut.test('test_binary_rightShift', () {
1875 final __test = new ConstantEvaluatorTest();
1876 runJUnitTest(__test, __test.test_binary_rightShift);
1877 });
1878 _ut.test('test_binary_times_double', () {
1879 final __test = new ConstantEvaluatorTest();
1880 runJUnitTest(__test, __test.test_binary_times_double);
1881 });
1882 _ut.test('test_binary_times_integer', () {
1883 final __test = new ConstantEvaluatorTest();
1884 runJUnitTest(__test, __test.test_binary_times_integer);
1885 });
1886 _ut.test('test_binary_truncatingDivide_double', () {
1887 final __test = new ConstantEvaluatorTest();
1888 runJUnitTest(__test, __test.test_binary_truncatingDivide_double);
1889 });
1890 _ut.test('test_binary_truncatingDivide_integer', () {
1891 final __test = new ConstantEvaluatorTest();
1892 runJUnitTest(__test, __test.test_binary_truncatingDivide_integer);
1893 });
1894 _ut.test('test_literal_boolean_false', () {
1895 final __test = new ConstantEvaluatorTest();
1896 runJUnitTest(__test, __test.test_literal_boolean_false);
1897 });
1898 _ut.test('test_literal_boolean_true', () {
1899 final __test = new ConstantEvaluatorTest();
1900 runJUnitTest(__test, __test.test_literal_boolean_true);
1901 });
1902 _ut.test('test_literal_list', () {
1903 final __test = new ConstantEvaluatorTest();
1904 runJUnitTest(__test, __test.test_literal_list);
1905 });
1906 _ut.test('test_literal_map', () {
1907 final __test = new ConstantEvaluatorTest();
1908 runJUnitTest(__test, __test.test_literal_map);
1909 });
1910 _ut.test('test_literal_null', () {
1911 final __test = new ConstantEvaluatorTest();
1912 runJUnitTest(__test, __test.test_literal_null);
1913 });
1914 _ut.test('test_literal_number_double', () {
1915 final __test = new ConstantEvaluatorTest();
1916 runJUnitTest(__test, __test.test_literal_number_double);
1917 });
1918 _ut.test('test_literal_number_integer', () {
1919 final __test = new ConstantEvaluatorTest();
1920 runJUnitTest(__test, __test.test_literal_number_integer);
1921 });
1922 _ut.test('test_literal_string_adjacent', () {
1923 final __test = new ConstantEvaluatorTest();
1924 runJUnitTest(__test, __test.test_literal_string_adjacent);
1925 });
1926 _ut.test('test_literal_string_interpolation_invalid', () {
1927 final __test = new ConstantEvaluatorTest();
1928 runJUnitTest(__test, __test.test_literal_string_interpolation_invalid);
1929 });
1930 _ut.test('test_literal_string_interpolation_valid', () {
1931 final __test = new ConstantEvaluatorTest();
1932 runJUnitTest(__test, __test.test_literal_string_interpolation_valid);
1933 });
1934 _ut.test('test_literal_string_simple', () {
1935 final __test = new ConstantEvaluatorTest();
1936 runJUnitTest(__test, __test.test_literal_string_simple);
1937 });
1938 _ut.test('test_parenthesizedExpression', () {
1939 final __test = new ConstantEvaluatorTest();
1940 runJUnitTest(__test, __test.test_parenthesizedExpression);
1941 });
1942 _ut.test('test_unary_bitNot', () {
1943 final __test = new ConstantEvaluatorTest();
1944 runJUnitTest(__test, __test.test_unary_bitNot);
1945 });
1946 _ut.test('test_unary_logicalNot', () {
1947 final __test = new ConstantEvaluatorTest();
1948 runJUnitTest(__test, __test.test_unary_logicalNot);
1949 });
1950 _ut.test('test_unary_negated_double', () {
1951 final __test = new ConstantEvaluatorTest();
1952 runJUnitTest(__test, __test.test_unary_negated_double);
1953 });
1954 _ut.test('test_unary_negated_integer', () {
1955 final __test = new ConstantEvaluatorTest();
1956 runJUnitTest(__test, __test.test_unary_negated_integer);
1957 });
1958 });
1959 }
1960 }
1961
1962 class SimpleStringLiteralTest extends ParserTestCase { 357 class SimpleStringLiteralTest extends ParserTestCase {
1963 void test_getValueOffset() { 358 void test_getValueOffset() {
1964 JUnitTestCase.assertEquals(1, new SimpleStringLiteral(TokenFactory.tokenFrom String("'X'"), "X").valueOffset); 359 JUnitTestCase.assertEquals(1, new SimpleStringLiteral(TokenFactory.tokenFrom String("'X'"), "X").valueOffset);
1965 JUnitTestCase.assertEquals(1, new SimpleStringLiteral(TokenFactory.tokenFrom String("\"X\""), "X").valueOffset); 360 JUnitTestCase.assertEquals(1, new SimpleStringLiteral(TokenFactory.tokenFrom String("\"X\""), "X").valueOffset);
1966 JUnitTestCase.assertEquals(3, new SimpleStringLiteral(TokenFactory.tokenFrom String("\"\"\"X\"\"\""), "X").valueOffset); 361 JUnitTestCase.assertEquals(3, new SimpleStringLiteral(TokenFactory.tokenFrom String("\"\"\"X\"\"\""), "X").valueOffset);
1967 JUnitTestCase.assertEquals(3, new SimpleStringLiteral(TokenFactory.tokenFrom String("'''X'''"), "X").valueOffset); 362 JUnitTestCase.assertEquals(3, new SimpleStringLiteral(TokenFactory.tokenFrom String("'''X'''"), "X").valueOffset);
1968 JUnitTestCase.assertEquals(2, new SimpleStringLiteral(TokenFactory.tokenFrom String("r'X'"), "X").valueOffset); 363 JUnitTestCase.assertEquals(2, new SimpleStringLiteral(TokenFactory.tokenFrom String("r'X'"), "X").valueOffset);
1969 JUnitTestCase.assertEquals(2, new SimpleStringLiteral(TokenFactory.tokenFrom String("r\"X\""), "X").valueOffset); 364 JUnitTestCase.assertEquals(2, new SimpleStringLiteral(TokenFactory.tokenFrom String("r\"X\""), "X").valueOffset);
1970 JUnitTestCase.assertEquals(4, new SimpleStringLiteral(TokenFactory.tokenFrom String("r\"\"\"X\"\"\""), "X").valueOffset); 365 JUnitTestCase.assertEquals(4, new SimpleStringLiteral(TokenFactory.tokenFrom String("r\"\"\"X\"\"\""), "X").valueOffset);
1971 JUnitTestCase.assertEquals(4, new SimpleStringLiteral(TokenFactory.tokenFrom String("r'''X'''"), "X").valueOffset); 366 JUnitTestCase.assertEquals(4, new SimpleStringLiteral(TokenFactory.tokenFrom String("r'''X'''"), "X").valueOffset);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2017 runJUnitTest(__test, __test.test_isRaw); 412 runJUnitTest(__test, __test.test_isRaw);
2018 }); 413 });
2019 _ut.test('test_simple', () { 414 _ut.test('test_simple', () {
2020 final __test = new SimpleStringLiteralTest(); 415 final __test = new SimpleStringLiteralTest();
2021 runJUnitTest(__test, __test.test_simple); 416 runJUnitTest(__test, __test.test_simple);
2022 }); 417 });
2023 }); 418 });
2024 } 419 }
2025 } 420 }
2026 421
422 class ConstantEvaluatorTest extends ParserTestCase {
423 void fail_constructor() {
424 Object value = _getConstantValue("?");
425 JUnitTestCase.assertEquals(null, value);
426 }
427
428 void fail_identifier_class() {
429 Object value = _getConstantValue("?");
430 JUnitTestCase.assertEquals(null, value);
431 }
432
433 void fail_identifier_function() {
434 Object value = _getConstantValue("?");
435 JUnitTestCase.assertEquals(null, value);
436 }
437
438 void fail_identifier_static() {
439 Object value = _getConstantValue("?");
440 JUnitTestCase.assertEquals(null, value);
441 }
442
443 void fail_identifier_staticMethod() {
444 Object value = _getConstantValue("?");
445 JUnitTestCase.assertEquals(null, value);
446 }
447
448 void fail_identifier_topLevel() {
449 Object value = _getConstantValue("?");
450 JUnitTestCase.assertEquals(null, value);
451 }
452
453 void fail_identifier_typeParameter() {
454 Object value = _getConstantValue("?");
455 JUnitTestCase.assertEquals(null, value);
456 }
457
458 void test_binary_bitAnd() {
459 Object value = _getConstantValue("74 & 42");
460 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
461 JUnitTestCase.assertEquals(74 & 42, value as int);
462 }
463
464 void test_binary_bitOr() {
465 Object value = _getConstantValue("74 | 42");
466 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
467 JUnitTestCase.assertEquals(74 | 42, value as int);
468 }
469
470 void test_binary_bitXor() {
471 Object value = _getConstantValue("74 ^ 42");
472 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
473 JUnitTestCase.assertEquals(74 ^ 42, value as int);
474 }
475
476 void test_binary_divide_double() {
477 Object value = _getConstantValue("3.2 / 2.3");
478 EngineTestCase.assertInstanceOf((obj) => obj is double, double, value);
479 JUnitTestCase.assertEquals(3.2 / 2.3, value as double);
480 }
481
482 void test_binary_divide_integer() {
483 Object value = _getConstantValue("3 / 2");
484 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
485 JUnitTestCase.assertEquals(1, value as int);
486 }
487
488 void test_binary_equal_boolean() {
489 Object value = _getConstantValue("true == false");
490 JUnitTestCase.assertEquals(false, value);
491 }
492
493 void test_binary_equal_integer() {
494 Object value = _getConstantValue("2 == 3");
495 JUnitTestCase.assertEquals(false, value);
496 }
497
498 void test_binary_equal_invalidLeft() {
499 Object value = _getConstantValue("a == 3");
500 JUnitTestCase.assertEquals(ConstantEvaluator.NOT_A_CONSTANT, value);
501 }
502
503 void test_binary_equal_invalidRight() {
504 Object value = _getConstantValue("2 == a");
505 JUnitTestCase.assertEquals(ConstantEvaluator.NOT_A_CONSTANT, value);
506 }
507
508 void test_binary_equal_string() {
509 Object value = _getConstantValue("'a' == 'b'");
510 JUnitTestCase.assertEquals(false, value);
511 }
512
513 void test_binary_greaterThan() {
514 Object value = _getConstantValue("2 > 3");
515 JUnitTestCase.assertEquals(false, value);
516 }
517
518 void test_binary_greaterThanOrEqual() {
519 Object value = _getConstantValue("2 >= 3");
520 JUnitTestCase.assertEquals(false, value);
521 }
522
523 void test_binary_leftShift() {
524 Object value = _getConstantValue("16 << 2");
525 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
526 JUnitTestCase.assertEquals(64, value as int);
527 }
528
529 void test_binary_lessThan() {
530 Object value = _getConstantValue("2 < 3");
531 JUnitTestCase.assertEquals(true, value);
532 }
533
534 void test_binary_lessThanOrEqual() {
535 Object value = _getConstantValue("2 <= 3");
536 JUnitTestCase.assertEquals(true, value);
537 }
538
539 void test_binary_logicalAnd() {
540 Object value = _getConstantValue("true && false");
541 JUnitTestCase.assertEquals(false, value);
542 }
543
544 void test_binary_logicalOr() {
545 Object value = _getConstantValue("true || false");
546 JUnitTestCase.assertEquals(true, value);
547 }
548
549 void test_binary_minus_double() {
550 Object value = _getConstantValue("3.2 - 2.3");
551 EngineTestCase.assertInstanceOf((obj) => obj is double, double, value);
552 JUnitTestCase.assertEquals(3.2 - 2.3, value as double);
553 }
554
555 void test_binary_minus_integer() {
556 Object value = _getConstantValue("3 - 2");
557 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
558 JUnitTestCase.assertEquals(1, value as int);
559 }
560
561 void test_binary_notEqual_boolean() {
562 Object value = _getConstantValue("true != false");
563 JUnitTestCase.assertEquals(true, value);
564 }
565
566 void test_binary_notEqual_integer() {
567 Object value = _getConstantValue("2 != 3");
568 JUnitTestCase.assertEquals(true, value);
569 }
570
571 void test_binary_notEqual_invalidLeft() {
572 Object value = _getConstantValue("a != 3");
573 JUnitTestCase.assertEquals(ConstantEvaluator.NOT_A_CONSTANT, value);
574 }
575
576 void test_binary_notEqual_invalidRight() {
577 Object value = _getConstantValue("2 != a");
578 JUnitTestCase.assertEquals(ConstantEvaluator.NOT_A_CONSTANT, value);
579 }
580
581 void test_binary_notEqual_string() {
582 Object value = _getConstantValue("'a' != 'b'");
583 JUnitTestCase.assertEquals(true, value);
584 }
585
586 void test_binary_plus_double() {
587 Object value = _getConstantValue("2.3 + 3.2");
588 EngineTestCase.assertInstanceOf((obj) => obj is double, double, value);
589 JUnitTestCase.assertEquals(2.3 + 3.2, value as double);
590 }
591
592 void test_binary_plus_integer() {
593 Object value = _getConstantValue("2 + 3");
594 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
595 JUnitTestCase.assertEquals(5, value as int);
596 }
597
598 void test_binary_remainder_double() {
599 Object value = _getConstantValue("3.2 % 2.3");
600 EngineTestCase.assertInstanceOf((obj) => obj is double, double, value);
601 JUnitTestCase.assertEquals(3.2 % 2.3, value as double);
602 }
603
604 void test_binary_remainder_integer() {
605 Object value = _getConstantValue("8 % 3");
606 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
607 JUnitTestCase.assertEquals(2, value as int);
608 }
609
610 void test_binary_rightShift() {
611 Object value = _getConstantValue("64 >> 2");
612 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
613 JUnitTestCase.assertEquals(16, value as int);
614 }
615
616 void test_binary_times_double() {
617 Object value = _getConstantValue("2.3 * 3.2");
618 EngineTestCase.assertInstanceOf((obj) => obj is double, double, value);
619 JUnitTestCase.assertEquals(2.3 * 3.2, value as double);
620 }
621
622 void test_binary_times_integer() {
623 Object value = _getConstantValue("2 * 3");
624 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
625 JUnitTestCase.assertEquals(6, value as int);
626 }
627
628 void test_binary_truncatingDivide_double() {
629 Object value = _getConstantValue("3.2 ~/ 2.3");
630 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
631 JUnitTestCase.assertEquals(1, value as int);
632 }
633
634 void test_binary_truncatingDivide_integer() {
635 Object value = _getConstantValue("10 ~/ 3");
636 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
637 JUnitTestCase.assertEquals(3, value as int);
638 }
639
640 void test_literal_boolean_false() {
641 Object value = _getConstantValue("false");
642 JUnitTestCase.assertEquals(false, value);
643 }
644
645 void test_literal_boolean_true() {
646 Object value = _getConstantValue("true");
647 JUnitTestCase.assertEquals(true, value);
648 }
649
650 void test_literal_list() {
651 Object value = _getConstantValue("['a', 'b', 'c']");
652 EngineTestCase.assertInstanceOf((obj) => obj is List, List, value);
653 List list = value as List;
654 JUnitTestCase.assertEquals(3, list.length);
655 JUnitTestCase.assertEquals("a", list[0]);
656 JUnitTestCase.assertEquals("b", list[1]);
657 JUnitTestCase.assertEquals("c", list[2]);
658 }
659
660 void test_literal_map() {
661 Object value = _getConstantValue("{'a' : 'm', 'b' : 'n', 'c' : 'o'}");
662 EngineTestCase.assertInstanceOf((obj) => obj is Map, Map, value);
663 Map map = value as Map;
664 JUnitTestCase.assertEquals(3, map.length);
665 JUnitTestCase.assertEquals("m", map["a"]);
666 JUnitTestCase.assertEquals("n", map["b"]);
667 JUnitTestCase.assertEquals("o", map["c"]);
668 }
669
670 void test_literal_null() {
671 Object value = _getConstantValue("null");
672 JUnitTestCase.assertEquals(null, value);
673 }
674
675 void test_literal_number_double() {
676 Object value = _getConstantValue("3.45");
677 EngineTestCase.assertInstanceOf((obj) => obj is double, double, value);
678 JUnitTestCase.assertEquals(3.45, value as double);
679 }
680
681 void test_literal_number_integer() {
682 Object value = _getConstantValue("42");
683 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
684 JUnitTestCase.assertEquals(42, value as int);
685 }
686
687 void test_literal_string_adjacent() {
688 Object value = _getConstantValue("'abc' 'def'");
689 JUnitTestCase.assertEquals("abcdef", value);
690 }
691
692 void test_literal_string_interpolation_invalid() {
693 Object value = _getConstantValue("'a\${f()}c'");
694 JUnitTestCase.assertEquals(ConstantEvaluator.NOT_A_CONSTANT, value);
695 }
696
697 void test_literal_string_interpolation_valid() {
698 Object value = _getConstantValue("'a\${3}c'");
699 JUnitTestCase.assertEquals("a3c", value);
700 }
701
702 void test_literal_string_simple() {
703 Object value = _getConstantValue("'abc'");
704 JUnitTestCase.assertEquals("abc", value);
705 }
706
707 void test_parenthesizedExpression() {
708 Object value = _getConstantValue("('a')");
709 JUnitTestCase.assertEquals("a", value);
710 }
711
712 void test_unary_bitNot() {
713 Object value = _getConstantValue("~42");
714 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
715 JUnitTestCase.assertEquals(~42, value as int);
716 }
717
718 void test_unary_logicalNot() {
719 Object value = _getConstantValue("!true");
720 JUnitTestCase.assertEquals(false, value);
721 }
722
723 void test_unary_negated_double() {
724 Object value = _getConstantValue("-42.3");
725 EngineTestCase.assertInstanceOf((obj) => obj is double, double, value);
726 JUnitTestCase.assertEquals(-42.3, value as double);
727 }
728
729 void test_unary_negated_integer() {
730 Object value = _getConstantValue("-42");
731 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
732 JUnitTestCase.assertEquals(-42, value as int);
733 }
734
735 Object _getConstantValue(String source) => ParserTestCase.parseExpression(sour ce, []).accept(new ConstantEvaluator());
736
737 static dartSuite() {
738 _ut.group('ConstantEvaluatorTest', () {
739 _ut.test('test_binary_bitAnd', () {
740 final __test = new ConstantEvaluatorTest();
741 runJUnitTest(__test, __test.test_binary_bitAnd);
742 });
743 _ut.test('test_binary_bitOr', () {
744 final __test = new ConstantEvaluatorTest();
745 runJUnitTest(__test, __test.test_binary_bitOr);
746 });
747 _ut.test('test_binary_bitXor', () {
748 final __test = new ConstantEvaluatorTest();
749 runJUnitTest(__test, __test.test_binary_bitXor);
750 });
751 _ut.test('test_binary_divide_double', () {
752 final __test = new ConstantEvaluatorTest();
753 runJUnitTest(__test, __test.test_binary_divide_double);
754 });
755 _ut.test('test_binary_divide_integer', () {
756 final __test = new ConstantEvaluatorTest();
757 runJUnitTest(__test, __test.test_binary_divide_integer);
758 });
759 _ut.test('test_binary_equal_boolean', () {
760 final __test = new ConstantEvaluatorTest();
761 runJUnitTest(__test, __test.test_binary_equal_boolean);
762 });
763 _ut.test('test_binary_equal_integer', () {
764 final __test = new ConstantEvaluatorTest();
765 runJUnitTest(__test, __test.test_binary_equal_integer);
766 });
767 _ut.test('test_binary_equal_invalidLeft', () {
768 final __test = new ConstantEvaluatorTest();
769 runJUnitTest(__test, __test.test_binary_equal_invalidLeft);
770 });
771 _ut.test('test_binary_equal_invalidRight', () {
772 final __test = new ConstantEvaluatorTest();
773 runJUnitTest(__test, __test.test_binary_equal_invalidRight);
774 });
775 _ut.test('test_binary_equal_string', () {
776 final __test = new ConstantEvaluatorTest();
777 runJUnitTest(__test, __test.test_binary_equal_string);
778 });
779 _ut.test('test_binary_greaterThan', () {
780 final __test = new ConstantEvaluatorTest();
781 runJUnitTest(__test, __test.test_binary_greaterThan);
782 });
783 _ut.test('test_binary_greaterThanOrEqual', () {
784 final __test = new ConstantEvaluatorTest();
785 runJUnitTest(__test, __test.test_binary_greaterThanOrEqual);
786 });
787 _ut.test('test_binary_leftShift', () {
788 final __test = new ConstantEvaluatorTest();
789 runJUnitTest(__test, __test.test_binary_leftShift);
790 });
791 _ut.test('test_binary_lessThan', () {
792 final __test = new ConstantEvaluatorTest();
793 runJUnitTest(__test, __test.test_binary_lessThan);
794 });
795 _ut.test('test_binary_lessThanOrEqual', () {
796 final __test = new ConstantEvaluatorTest();
797 runJUnitTest(__test, __test.test_binary_lessThanOrEqual);
798 });
799 _ut.test('test_binary_logicalAnd', () {
800 final __test = new ConstantEvaluatorTest();
801 runJUnitTest(__test, __test.test_binary_logicalAnd);
802 });
803 _ut.test('test_binary_logicalOr', () {
804 final __test = new ConstantEvaluatorTest();
805 runJUnitTest(__test, __test.test_binary_logicalOr);
806 });
807 _ut.test('test_binary_minus_double', () {
808 final __test = new ConstantEvaluatorTest();
809 runJUnitTest(__test, __test.test_binary_minus_double);
810 });
811 _ut.test('test_binary_minus_integer', () {
812 final __test = new ConstantEvaluatorTest();
813 runJUnitTest(__test, __test.test_binary_minus_integer);
814 });
815 _ut.test('test_binary_notEqual_boolean', () {
816 final __test = new ConstantEvaluatorTest();
817 runJUnitTest(__test, __test.test_binary_notEqual_boolean);
818 });
819 _ut.test('test_binary_notEqual_integer', () {
820 final __test = new ConstantEvaluatorTest();
821 runJUnitTest(__test, __test.test_binary_notEqual_integer);
822 });
823 _ut.test('test_binary_notEqual_invalidLeft', () {
824 final __test = new ConstantEvaluatorTest();
825 runJUnitTest(__test, __test.test_binary_notEqual_invalidLeft);
826 });
827 _ut.test('test_binary_notEqual_invalidRight', () {
828 final __test = new ConstantEvaluatorTest();
829 runJUnitTest(__test, __test.test_binary_notEqual_invalidRight);
830 });
831 _ut.test('test_binary_notEqual_string', () {
832 final __test = new ConstantEvaluatorTest();
833 runJUnitTest(__test, __test.test_binary_notEqual_string);
834 });
835 _ut.test('test_binary_plus_double', () {
836 final __test = new ConstantEvaluatorTest();
837 runJUnitTest(__test, __test.test_binary_plus_double);
838 });
839 _ut.test('test_binary_plus_integer', () {
840 final __test = new ConstantEvaluatorTest();
841 runJUnitTest(__test, __test.test_binary_plus_integer);
842 });
843 _ut.test('test_binary_remainder_double', () {
844 final __test = new ConstantEvaluatorTest();
845 runJUnitTest(__test, __test.test_binary_remainder_double);
846 });
847 _ut.test('test_binary_remainder_integer', () {
848 final __test = new ConstantEvaluatorTest();
849 runJUnitTest(__test, __test.test_binary_remainder_integer);
850 });
851 _ut.test('test_binary_rightShift', () {
852 final __test = new ConstantEvaluatorTest();
853 runJUnitTest(__test, __test.test_binary_rightShift);
854 });
855 _ut.test('test_binary_times_double', () {
856 final __test = new ConstantEvaluatorTest();
857 runJUnitTest(__test, __test.test_binary_times_double);
858 });
859 _ut.test('test_binary_times_integer', () {
860 final __test = new ConstantEvaluatorTest();
861 runJUnitTest(__test, __test.test_binary_times_integer);
862 });
863 _ut.test('test_binary_truncatingDivide_double', () {
864 final __test = new ConstantEvaluatorTest();
865 runJUnitTest(__test, __test.test_binary_truncatingDivide_double);
866 });
867 _ut.test('test_binary_truncatingDivide_integer', () {
868 final __test = new ConstantEvaluatorTest();
869 runJUnitTest(__test, __test.test_binary_truncatingDivide_integer);
870 });
871 _ut.test('test_literal_boolean_false', () {
872 final __test = new ConstantEvaluatorTest();
873 runJUnitTest(__test, __test.test_literal_boolean_false);
874 });
875 _ut.test('test_literal_boolean_true', () {
876 final __test = new ConstantEvaluatorTest();
877 runJUnitTest(__test, __test.test_literal_boolean_true);
878 });
879 _ut.test('test_literal_list', () {
880 final __test = new ConstantEvaluatorTest();
881 runJUnitTest(__test, __test.test_literal_list);
882 });
883 _ut.test('test_literal_map', () {
884 final __test = new ConstantEvaluatorTest();
885 runJUnitTest(__test, __test.test_literal_map);
886 });
887 _ut.test('test_literal_null', () {
888 final __test = new ConstantEvaluatorTest();
889 runJUnitTest(__test, __test.test_literal_null);
890 });
891 _ut.test('test_literal_number_double', () {
892 final __test = new ConstantEvaluatorTest();
893 runJUnitTest(__test, __test.test_literal_number_double);
894 });
895 _ut.test('test_literal_number_integer', () {
896 final __test = new ConstantEvaluatorTest();
897 runJUnitTest(__test, __test.test_literal_number_integer);
898 });
899 _ut.test('test_literal_string_adjacent', () {
900 final __test = new ConstantEvaluatorTest();
901 runJUnitTest(__test, __test.test_literal_string_adjacent);
902 });
903 _ut.test('test_literal_string_interpolation_invalid', () {
904 final __test = new ConstantEvaluatorTest();
905 runJUnitTest(__test, __test.test_literal_string_interpolation_invalid);
906 });
907 _ut.test('test_literal_string_interpolation_valid', () {
908 final __test = new ConstantEvaluatorTest();
909 runJUnitTest(__test, __test.test_literal_string_interpolation_valid);
910 });
911 _ut.test('test_literal_string_simple', () {
912 final __test = new ConstantEvaluatorTest();
913 runJUnitTest(__test, __test.test_literal_string_simple);
914 });
915 _ut.test('test_parenthesizedExpression', () {
916 final __test = new ConstantEvaluatorTest();
917 runJUnitTest(__test, __test.test_parenthesizedExpression);
918 });
919 _ut.test('test_unary_bitNot', () {
920 final __test = new ConstantEvaluatorTest();
921 runJUnitTest(__test, __test.test_unary_bitNot);
922 });
923 _ut.test('test_unary_logicalNot', () {
924 final __test = new ConstantEvaluatorTest();
925 runJUnitTest(__test, __test.test_unary_logicalNot);
926 });
927 _ut.test('test_unary_negated_double', () {
928 final __test = new ConstantEvaluatorTest();
929 runJUnitTest(__test, __test.test_unary_negated_double);
930 });
931 _ut.test('test_unary_negated_integer', () {
932 final __test = new ConstantEvaluatorTest();
933 runJUnitTest(__test, __test.test_unary_negated_integer);
934 });
935 });
936 }
937 }
938
2027 class ToSourceVisitorTest extends EngineTestCase { 939 class ToSourceVisitorTest extends EngineTestCase {
2028 void test_visitAdjacentStrings() { 940 void test_visitAdjacentStrings() {
2029 _assertSource("'a' 'b'", AstFactory.adjacentStrings([AstFactory.string2("a") , AstFactory.string2("b")])); 941 _assertSource("'a' 'b'", AstFactory.adjacentStrings([AstFactory.string2("a") , AstFactory.string2("b")]));
2030 } 942 }
2031 943
2032 void test_visitAnnotation_constant() { 944 void test_visitAnnotation_constant() {
2033 _assertSource("@A", AstFactory.annotation(AstFactory.identifier3("A"))); 945 _assertSource("@A", AstFactory.annotation(AstFactory.identifier3("A")));
2034 } 946 }
2035 947
2036 void test_visitAnnotation_constructor() { 948 void test_visitAnnotation_constructor() {
(...skipping 2221 matching lines...) Expand 10 before | Expand all | Expand 10 after
4258 _ut.test('test_visitWithClause_multiple', () { 3170 _ut.test('test_visitWithClause_multiple', () {
4259 final __test = new ToSourceVisitorTest(); 3171 final __test = new ToSourceVisitorTest();
4260 runJUnitTest(__test, __test.test_visitWithClause_multiple); 3172 runJUnitTest(__test, __test.test_visitWithClause_multiple);
4261 }); 3173 });
4262 _ut.test('test_visitWithClause_single', () { 3174 _ut.test('test_visitWithClause_single', () {
4263 final __test = new ToSourceVisitorTest(); 3175 final __test = new ToSourceVisitorTest();
4264 runJUnitTest(__test, __test.test_visitWithClause_single); 3176 runJUnitTest(__test, __test.test_visitWithClause_single);
4265 }); 3177 });
4266 }); 3178 });
4267 } 3179 }
3180 }
3181
3182 class NodeLocatorTest extends ParserTestCase {
3183 void test_range() {
3184 CompilationUnit unit = ParserTestCase.parseCompilationUnit("library myLib;", []);
3185 _assertLocate(unit, 4, 10, (node) => node is LibraryDirective, LibraryDirect ive);
3186 }
3187
3188 void test_searchWithin_null() {
3189 NodeLocator locator = new NodeLocator.con2(0, 0);
3190 JUnitTestCase.assertNull(locator.searchWithin(null));
3191 }
3192
3193 void test_searchWithin_offset() {
3194 CompilationUnit unit = ParserTestCase.parseCompilationUnit("library myLib;", []);
3195 _assertLocate(unit, 10, 10, (node) => node is SimpleIdentifier, SimpleIdenti fier);
3196 }
3197
3198 void test_searchWithin_offsetAfterNode() {
3199 CompilationUnit unit = ParserTestCase.parseCompilationUnit(EngineTestCase.cr eateSource(["class A {}", "class B {}"]), []);
3200 NodeLocator locator = new NodeLocator.con2(1024, 1024);
3201 AstNode node = locator.searchWithin(unit.declarations[0]);
3202 JUnitTestCase.assertNull(node);
3203 }
3204
3205 void test_searchWithin_offsetBeforeNode() {
3206 CompilationUnit unit = ParserTestCase.parseCompilationUnit(EngineTestCase.cr eateSource(["class A {}", "class B {}"]), []);
3207 NodeLocator locator = new NodeLocator.con2(0, 0);
3208 AstNode node = locator.searchWithin(unit.declarations[1]);
3209 JUnitTestCase.assertNull(node);
3210 }
3211
3212 void _assertLocate(CompilationUnit unit, int start, int end, Predicate<AstNode > predicate, Type expectedClass) {
3213 NodeLocator locator = new NodeLocator.con2(start, end);
3214 AstNode node = locator.searchWithin(unit);
3215 JUnitTestCase.assertNotNull(node);
3216 JUnitTestCase.assertSame(node, locator.foundNode);
3217 JUnitTestCase.assertTrueMsg("Node starts after range", node.offset <= start) ;
3218 JUnitTestCase.assertTrueMsg("Node ends before range", node.offset + node.len gth > end);
3219 EngineTestCase.assertInstanceOf(predicate, expectedClass, node);
3220 }
3221
3222 static dartSuite() {
3223 _ut.group('NodeLocatorTest', () {
3224 _ut.test('test_range', () {
3225 final __test = new NodeLocatorTest();
3226 runJUnitTest(__test, __test.test_range);
3227 });
3228 _ut.test('test_searchWithin_null', () {
3229 final __test = new NodeLocatorTest();
3230 runJUnitTest(__test, __test.test_searchWithin_null);
3231 });
3232 _ut.test('test_searchWithin_offset', () {
3233 final __test = new NodeLocatorTest();
3234 runJUnitTest(__test, __test.test_searchWithin_offset);
3235 });
3236 _ut.test('test_searchWithin_offsetAfterNode', () {
3237 final __test = new NodeLocatorTest();
3238 runJUnitTest(__test, __test.test_searchWithin_offsetAfterNode);
3239 });
3240 _ut.test('test_searchWithin_offsetBeforeNode', () {
3241 final __test = new NodeLocatorTest();
3242 runJUnitTest(__test, __test.test_searchWithin_offsetBeforeNode);
3243 });
3244 });
3245 }
3246 }
3247
3248 /**
3249 * The class `AstFactory` defines utility methods that can be used to create AST nodes. The
3250 * nodes that are created are complete in the sense that all of the tokens that would have been
3251 * associated with the nodes by a parser are also created, but the token stream is not constructed.
3252 * None of the nodes are resolved.
3253 *
3254 * The general pattern is for the name of the factory method to be the same as t he name of the class
3255 * of AST node being created. There are two notable exceptions. The first is for methods creating
3256 * nodes that are part of a cascade expression. These methods are all prefixed w ith 'cascaded'. The
3257 * second is places where a shorter name seemed unambiguous and easier to read, such as using
3258 * 'identifier' rather than 'prefixedIdentifier', or 'integer' rather than 'inte gerLiteral'.
3259 */
3260 class AstFactory {
3261 static AdjacentStrings adjacentStrings(List<StringLiteral> strings) => new Adj acentStrings(list(strings));
3262
3263 static Annotation annotation(Identifier name) => new Annotation(TokenFactory.t okenFromType(TokenType.AT), name, null, null, null);
3264
3265 static Annotation annotation2(Identifier name, SimpleIdentifier constructorNam e, ArgumentList arguments) => new Annotation(TokenFactory.tokenFromType(TokenTyp e.AT), name, TokenFactory.tokenFromType(TokenType.PERIOD), constructorName, argu ments);
3266
3267 static ArgumentDefinitionTest argumentDefinitionTest(String identifier) => new ArgumentDefinitionTest(TokenFactory.tokenFromType(TokenType.QUESTION), identifi er3(identifier));
3268
3269 static ArgumentList argumentList(List<Expression> arguments) => new ArgumentLi st(TokenFactory.tokenFromType(TokenType.OPEN_PAREN), list(arguments), TokenFacto ry.tokenFromType(TokenType.CLOSE_PAREN));
3270
3271 static AsExpression asExpression(Expression expression, TypeName type) => new AsExpression(expression, TokenFactory.tokenFromKeyword(Keyword.AS), type);
3272
3273 static AssertStatement assertStatement(Expression condition) => new AssertStat ement(TokenFactory.tokenFromKeyword(Keyword.ASSERT), TokenFactory.tokenFromType( TokenType.OPEN_PAREN), condition, TokenFactory.tokenFromType(TokenType.CLOSE_PAR EN), TokenFactory.tokenFromType(TokenType.SEMICOLON));
3274
3275 static AssignmentExpression assignmentExpression(Expression leftHandSide, Toke nType operator, Expression rightHandSide) => new AssignmentExpression(leftHandSi de, TokenFactory.tokenFromType(operator), rightHandSide);
3276
3277 static BinaryExpression binaryExpression(Expression leftOperand, TokenType ope rator, Expression rightOperand) => new BinaryExpression(leftOperand, TokenFactor y.tokenFromType(operator), rightOperand);
3278
3279 static Block block(List<Statement> statements) => new Block(TokenFactory.token FromType(TokenType.OPEN_CURLY_BRACKET), list(statements), TokenFactory.tokenFrom Type(TokenType.CLOSE_CURLY_BRACKET));
3280
3281 static BlockFunctionBody blockFunctionBody(Block block) => new BlockFunctionBo dy(block);
3282
3283 static BlockFunctionBody blockFunctionBody2(List<Statement> statements) => new BlockFunctionBody(block(statements));
3284
3285 static BooleanLiteral booleanLiteral(bool value) => new BooleanLiteral(value ? TokenFactory.tokenFromKeyword(Keyword.TRUE) : TokenFactory.tokenFromKeyword(Key word.FALSE), value);
3286
3287 static BreakStatement breakStatement() => new BreakStatement(TokenFactory.toke nFromKeyword(Keyword.BREAK), null, TokenFactory.tokenFromType(TokenType.SEMICOLO N));
3288
3289 static BreakStatement breakStatement2(String label) => new BreakStatement(Toke nFactory.tokenFromKeyword(Keyword.BREAK), identifier3(label), TokenFactory.token FromType(TokenType.SEMICOLON));
3290
3291 static IndexExpression cascadedIndexExpression(Expression index) => new IndexE xpression.forCascade(TokenFactory.tokenFromType(TokenType.PERIOD_PERIOD), TokenF actory.tokenFromType(TokenType.OPEN_SQUARE_BRACKET), index, TokenFactory.tokenFr omType(TokenType.CLOSE_SQUARE_BRACKET));
3292
3293 static MethodInvocation cascadedMethodInvocation(String methodName, List<Expre ssion> arguments) => new MethodInvocation(null, TokenFactory.tokenFromType(Token Type.PERIOD_PERIOD), identifier3(methodName), argumentList(arguments));
3294
3295 static PropertyAccess cascadedPropertyAccess(String propertyName) => new Prope rtyAccess(null, TokenFactory.tokenFromType(TokenType.PERIOD_PERIOD), identifier3 (propertyName));
3296
3297 static CascadeExpression cascadeExpression(Expression target, List<Expression> cascadeSections) => new CascadeExpression(target, list(cascadeSections));
3298
3299 static CatchClause catchClause(String exceptionParameter, List<Statement> stat ements) => catchClause5(null, exceptionParameter, null, statements);
3300
3301 static CatchClause catchClause2(String exceptionParameter, String stackTracePa rameter, List<Statement> statements) => catchClause5(null, exceptionParameter, s tackTraceParameter, statements);
3302
3303 static CatchClause catchClause3(TypeName exceptionType, List<Statement> statem ents) => catchClause5(exceptionType, null, null, statements);
3304
3305 static CatchClause catchClause4(TypeName exceptionType, String exceptionParame ter, List<Statement> statements) => catchClause5(exceptionType, exceptionParamet er, null, statements);
3306
3307 static CatchClause catchClause5(TypeName exceptionType, String exceptionParame ter, String stackTraceParameter, List<Statement> statements) => new CatchClause( exceptionType == null ? null : TokenFactory.tokenFromTypeAndString(TokenType.IDE NTIFIER, "on"), exceptionType, exceptionParameter == null ? null : TokenFactory. tokenFromKeyword(Keyword.CATCH), exceptionParameter == null ? null : TokenFactor y.tokenFromType(TokenType.OPEN_PAREN), exceptionParameter == null ? null : ident ifier3(exceptionParameter), stackTraceParameter == null ? null : TokenFactory.to kenFromType(TokenType.COMMA), stackTraceParameter == null ? null : identifier3(s tackTraceParameter), exceptionParameter == null ? null : TokenFactory.tokenFromT ype(TokenType.CLOSE_PAREN), block(statements));
3308
3309 static ClassDeclaration classDeclaration(Keyword abstractKeyword, String name, TypeParameterList typeParameters, ExtendsClause extendsClause, WithClause withC lause, ImplementsClause implementsClause, List<ClassMember> members) => new Clas sDeclaration(null, null, abstractKeyword == null ? null : TokenFactory.tokenFrom Keyword(abstractKeyword), TokenFactory.tokenFromKeyword(Keyword.CLASS), identifi er3(name), typeParameters, extendsClause, withClause, implementsClause, TokenFac tory.tokenFromType(TokenType.OPEN_CURLY_BRACKET), list(members), TokenFactory.to kenFromType(TokenType.CLOSE_CURLY_BRACKET));
3310
3311 static ClassTypeAlias classTypeAlias(String name, TypeParameterList typeParame ters, Keyword abstractKeyword, TypeName superclass, WithClause withClause, Imple mentsClause implementsClause) => new ClassTypeAlias(null, null, TokenFactory.tok enFromKeyword(Keyword.CLASS), identifier3(name), typeParameters, TokenFactory.to kenFromType(TokenType.EQ), abstractKeyword == null ? null : TokenFactory.tokenFr omKeyword(abstractKeyword), superclass, withClause, implementsClause, TokenFacto ry.tokenFromType(TokenType.SEMICOLON));
3312
3313 static CompilationUnit compilationUnit() => compilationUnit8(null, null, null) ;
3314
3315 static CompilationUnit compilationUnit2(List<CompilationUnitMember> declaratio ns) => compilationUnit8(null, null, list(declarations));
3316
3317 static CompilationUnit compilationUnit3(List<Directive> directives) => compila tionUnit8(null, list(directives), null);
3318
3319 static CompilationUnit compilationUnit4(List<Directive> directives, List<Compi lationUnitMember> declarations) => compilationUnit8(null, directives, declaratio ns);
3320
3321 static CompilationUnit compilationUnit5(String scriptTag) => compilationUnit8( scriptTag, null, null);
3322
3323 static CompilationUnit compilationUnit6(String scriptTag, List<CompilationUnit Member> declarations) => compilationUnit8(scriptTag, null, list(declarations));
3324
3325 static CompilationUnit compilationUnit7(String scriptTag, List<Directive> dire ctives) => compilationUnit8(scriptTag, list(directives), null);
3326
3327 static CompilationUnit compilationUnit8(String scriptTag, List<Directive> dire ctives, List<CompilationUnitMember> declarations) => new CompilationUnit(TokenFa ctory.tokenFromType(TokenType.EOF), scriptTag == null ? null : AstFactory.script Tag(scriptTag), directives == null ? new List<Directive>() : directives, declara tions == null ? new List<CompilationUnitMember>() : declarations, TokenFactory.t okenFromType(TokenType.EOF));
3328
3329 static ConditionalExpression conditionalExpression(Expression condition, Expre ssion thenExpression, Expression elseExpression) => new ConditionalExpression(co ndition, TokenFactory.tokenFromType(TokenType.QUESTION), thenExpression, TokenFa ctory.tokenFromType(TokenType.COLON), elseExpression);
3330
3331 static ConstructorDeclaration constructorDeclaration(Identifier returnType, St ring name, FormalParameterList parameters, List<ConstructorInitializer> initiali zers) => new ConstructorDeclaration(null, null, TokenFactory.tokenFromKeyword(Ke yword.EXTERNAL), null, null, returnType, name == null ? null : TokenFactory.toke nFromType(TokenType.PERIOD), name == null ? null : identifier3(name), parameters , initializers == null || initializers.isEmpty ? null : TokenFactory.tokenFromTy pe(TokenType.PERIOD), initializers == null ? new List<ConstructorInitializer>() : initializers, null, emptyFunctionBody());
3332
3333 static ConstructorDeclaration constructorDeclaration2(Keyword constKeyword, Ke yword factoryKeyword, Identifier returnType, String name, FormalParameterList pa rameters, List<ConstructorInitializer> initializers, FunctionBody body) => new C onstructorDeclaration(null, null, null, constKeyword == null ? null : TokenFacto ry.tokenFromKeyword(constKeyword), factoryKeyword == null ? null : TokenFactory. tokenFromKeyword(factoryKeyword), returnType, name == null ? null : TokenFactory .tokenFromType(TokenType.PERIOD), name == null ? null : identifier3(name), param eters, initializers == null || initializers.isEmpty ? null : TokenFactory.tokenF romType(TokenType.PERIOD), initializers == null ? new List<ConstructorInitialize r>() : initializers, null, body);
3334
3335 static ConstructorFieldInitializer constructorFieldInitializer(bool prefixedWi thThis, String fieldName, Expression expression) => new ConstructorFieldInitiali zer(prefixedWithThis ? TokenFactory.tokenFromKeyword(Keyword.THIS) : null, prefi xedWithThis ? TokenFactory.tokenFromType(TokenType.PERIOD) : null, identifier3(f ieldName), TokenFactory.tokenFromType(TokenType.EQ), expression);
3336
3337 static ConstructorName constructorName(TypeName type, String name) => new Cons tructorName(type, name == null ? null : TokenFactory.tokenFromType(TokenType.PER IOD), name == null ? null : identifier3(name));
3338
3339 static ContinueStatement continueStatement([String label]) {
3340 SimpleIdentifier labelNode = label == null ? null : identifier3(label);
3341 return new ContinueStatement(TokenFactory.tokenFromKeyword(Keyword.CONTINUE) , labelNode, TokenFactory.tokenFromType(TokenType.SEMICOLON));
3342 }
3343
3344 static DeclaredIdentifier declaredIdentifier(Keyword keyword, String identifie r) => declaredIdentifier2(keyword, null, identifier);
3345
3346 static DeclaredIdentifier declaredIdentifier2(Keyword keyword, TypeName type, String identifier) => new DeclaredIdentifier(null, null, keyword == null ? null : TokenFactory.tokenFromKeyword(keyword), type, identifier3(identifier));
3347
3348 static DeclaredIdentifier declaredIdentifier3(String identifier) => declaredId entifier2(null, null, identifier);
3349
3350 static DeclaredIdentifier declaredIdentifier4(TypeName type, String identifier ) => declaredIdentifier2(null, type, identifier);
3351
3352 static DoStatement doStatement(Statement body, Expression condition) => new Do Statement(TokenFactory.tokenFromKeyword(Keyword.DO), body, TokenFactory.tokenFro mKeyword(Keyword.WHILE), TokenFactory.tokenFromType(TokenType.OPEN_PAREN), condi tion, TokenFactory.tokenFromType(TokenType.CLOSE_PAREN), TokenFactory.tokenFromT ype(TokenType.SEMICOLON));
3353
3354 static DoubleLiteral doubleLiteral(double value) => new DoubleLiteral(TokenFac tory.tokenFromString(value.toString()), value);
3355
3356 static EmptyFunctionBody emptyFunctionBody() => new EmptyFunctionBody(TokenFac tory.tokenFromType(TokenType.SEMICOLON));
3357
3358 static EmptyStatement emptyStatement() => new EmptyStatement(TokenFactory.toke nFromType(TokenType.SEMICOLON));
3359
3360 static ExportDirective exportDirective(List<Annotation> metadata, String uri, List<Combinator> combinators) => new ExportDirective(null, metadata, TokenFactor y.tokenFromKeyword(Keyword.EXPORT), string2(uri), list(combinators), TokenFactor y.tokenFromType(TokenType.SEMICOLON));
3361
3362 static ExportDirective exportDirective2(String uri, List<Combinator> combinato rs) => exportDirective(new List<Annotation>(), uri, combinators);
3363
3364 static ExpressionFunctionBody expressionFunctionBody(Expression expression) => new ExpressionFunctionBody(TokenFactory.tokenFromType(TokenType.FUNCTION), expr ession, TokenFactory.tokenFromType(TokenType.SEMICOLON));
3365
3366 static ExpressionStatement expressionStatement(Expression expression) => new E xpressionStatement(expression, TokenFactory.tokenFromType(TokenType.SEMICOLON));
3367
3368 static ExtendsClause extendsClause(TypeName type) => new ExtendsClause(TokenFa ctory.tokenFromKeyword(Keyword.EXTENDS), type);
3369
3370 static FieldDeclaration fieldDeclaration(bool isStatic, Keyword keyword, TypeN ame type, List<VariableDeclaration> variables) => new FieldDeclaration(null, nul l, isStatic ? TokenFactory.tokenFromKeyword(Keyword.STATIC) : null, variableDecl arationList(keyword, type, variables), TokenFactory.tokenFromType(TokenType.SEMI COLON));
3371
3372 static FieldDeclaration fieldDeclaration2(bool isStatic, Keyword keyword, List <VariableDeclaration> variables) => fieldDeclaration(isStatic, keyword, null, va riables);
3373
3374 static FieldFormalParameter fieldFormalParameter(Keyword keyword, TypeName typ e, String identifier, [FormalParameterList parameterList]) => new FieldFormalPar ameter(null, null, keyword == null ? null : TokenFactory.tokenFromKeyword(keywor d), type, TokenFactory.tokenFromKeyword(Keyword.THIS), TokenFactory.tokenFromTyp e(TokenType.PERIOD), identifier3(identifier), parameterList);
3375
3376 static FieldFormalParameter fieldFormalParameter2(String identifier) => fieldF ormalParameter(null, null, identifier);
3377
3378 static ForEachStatement forEachStatement(DeclaredIdentifier loopVariable, Expr ession iterator, Statement body) => new ForEachStatement.con1(TokenFactory.token FromKeyword(Keyword.FOR), TokenFactory.tokenFromType(TokenType.OPEN_PAREN), loop Variable, TokenFactory.tokenFromKeyword(Keyword.IN), iterator, TokenFactory.toke nFromType(TokenType.CLOSE_PAREN), body);
3379
3380 static FormalParameterList formalParameterList(List<FormalParameter> parameter s) => new FormalParameterList(TokenFactory.tokenFromType(TokenType.OPEN_PAREN), list(parameters), null, null, TokenFactory.tokenFromType(TokenType.CLOSE_PAREN)) ;
3381
3382 static ForStatement forStatement(Expression initialization, Expression conditi on, List<Expression> updaters, Statement body) => new ForStatement(TokenFactory. tokenFromKeyword(Keyword.FOR), TokenFactory.tokenFromType(TokenType.OPEN_PAREN), null, initialization, TokenFactory.tokenFromType(TokenType.SEMICOLON), conditio n, TokenFactory.tokenFromType(TokenType.SEMICOLON), updaters, TokenFactory.token FromType(TokenType.CLOSE_PAREN), body);
3383
3384 static ForStatement forStatement2(VariableDeclarationList variableList, Expres sion condition, List<Expression> updaters, Statement body) => new ForStatement(T okenFactory.tokenFromKeyword(Keyword.FOR), TokenFactory.tokenFromType(TokenType. OPEN_PAREN), variableList, null, TokenFactory.tokenFromType(TokenType.SEMICOLON) , condition, TokenFactory.tokenFromType(TokenType.SEMICOLON), updaters, TokenFac tory.tokenFromType(TokenType.CLOSE_PAREN), body);
3385
3386 static FunctionDeclaration functionDeclaration(TypeName type, Keyword keyword, String name, FunctionExpression functionExpression) => new FunctionDeclaration( null, null, null, type, keyword == null ? null : TokenFactory.tokenFromKeyword(k eyword), identifier3(name), functionExpression);
3387
3388 static FunctionDeclarationStatement functionDeclarationStatement(TypeName type , Keyword keyword, String name, FunctionExpression functionExpression) => new Fu nctionDeclarationStatement(functionDeclaration(type, keyword, name, functionExpr ession));
3389
3390 static FunctionExpression functionExpression() => new FunctionExpression(forma lParameterList([]), blockFunctionBody2([]));
3391
3392 static FunctionExpression functionExpression2(FormalParameterList parameters, FunctionBody body) => new FunctionExpression(parameters, body);
3393
3394 static FunctionExpressionInvocation functionExpressionInvocation(Expression fu nction, List<Expression> arguments) => new FunctionExpressionInvocation(function , argumentList(arguments));
3395
3396 static FunctionTypedFormalParameter functionTypedFormalParameter(TypeName retu rnType, String identifier, List<FormalParameter> parameters) => new FunctionType dFormalParameter(null, null, returnType, identifier3(identifier), formalParamete rList(parameters));
3397
3398 static HideCombinator hideCombinator(List<SimpleIdentifier> identifiers) => ne w HideCombinator(TokenFactory.tokenFromString("hide"), list(identifiers));
3399
3400 static HideCombinator hideCombinator2(List<String> identifiers) {
3401 List<SimpleIdentifier> identifierList = new List<SimpleIdentifier>();
3402 for (String identifier in identifiers) {
3403 identifierList.add(identifier3(identifier));
3404 }
3405 return new HideCombinator(TokenFactory.tokenFromString("hide"), identifierLi st);
3406 }
3407
3408 static PrefixedIdentifier identifier(SimpleIdentifier prefix, SimpleIdentifier identifier) => new PrefixedIdentifier(prefix, TokenFactory.tokenFromType(TokenT ype.PERIOD), identifier);
3409
3410 static SimpleIdentifier identifier3(String lexeme) => new SimpleIdentifier(Tok enFactory.tokenFromTypeAndString(TokenType.IDENTIFIER, lexeme));
3411
3412 static PrefixedIdentifier identifier4(String prefix, SimpleIdentifier identifi er) => new PrefixedIdentifier(identifier3(prefix), TokenFactory.tokenFromType(To kenType.PERIOD), identifier);
3413
3414 static PrefixedIdentifier identifier5(String prefix, String identifier) => new PrefixedIdentifier(identifier3(prefix), TokenFactory.tokenFromType(TokenType.PE RIOD), identifier3(identifier));
3415
3416 static IfStatement ifStatement(Expression condition, Statement thenStatement) => ifStatement2(condition, thenStatement, null);
3417
3418 static IfStatement ifStatement2(Expression condition, Statement thenStatement, Statement elseStatement) => new IfStatement(TokenFactory.tokenFromKeyword(Keywo rd.IF), TokenFactory.tokenFromType(TokenType.OPEN_PAREN), condition, TokenFactor y.tokenFromType(TokenType.CLOSE_PAREN), thenStatement, elseStatement == null ? n ull : TokenFactory.tokenFromKeyword(Keyword.ELSE), elseStatement);
3419
3420 static ImplementsClause implementsClause(List<TypeName> types) => new Implemen tsClause(TokenFactory.tokenFromKeyword(Keyword.IMPLEMENTS), list(types));
3421
3422 static ImportDirective importDirective(List<Annotation> metadata, String uri, String prefix, List<Combinator> combinators) => new ImportDirective(null, metada ta, TokenFactory.tokenFromKeyword(Keyword.IMPORT), string2(uri), null, prefix == null ? null : TokenFactory.tokenFromKeyword(Keyword.AS), prefix == null ? null : identifier3(prefix), list(combinators), TokenFactory.tokenFromType(TokenType.S EMICOLON));
3423
3424 static ImportDirective importDirective2(String uri, String prefix, List<Combin ator> combinators) => importDirective(new List<Annotation>(), uri, prefix, combi nators);
3425
3426 static IndexExpression indexExpression(Expression array, Expression index) => new IndexExpression.forTarget(array, TokenFactory.tokenFromType(TokenType.OPEN_S QUARE_BRACKET), index, TokenFactory.tokenFromType(TokenType.CLOSE_SQUARE_BRACKET ));
3427
3428 static InstanceCreationExpression instanceCreationExpression(Keyword keyword, ConstructorName name, List<Expression> arguments) => new InstanceCreationExpress ion(keyword == null ? null : TokenFactory.tokenFromKeyword(keyword), name, argum entList(arguments));
3429
3430 static InstanceCreationExpression instanceCreationExpression2(Keyword keyword, TypeName type, List<Expression> arguments) => instanceCreationExpression3(keywo rd, type, null, arguments);
3431
3432 static InstanceCreationExpression instanceCreationExpression3(Keyword keyword, TypeName type, String identifier, List<Expression> arguments) => instanceCreati onExpression(keyword, new ConstructorName(type, identifier == null ? null : Toke nFactory.tokenFromType(TokenType.PERIOD), identifier == null ? null : identifier 3(identifier)), arguments);
3433
3434 static IntegerLiteral integer(int value) => new IntegerLiteral(TokenFactory.to kenFromTypeAndString(TokenType.INT, value.toString()), value);
3435
3436 static InterpolationExpression interpolationExpression(Expression expression) => new InterpolationExpression(TokenFactory.tokenFromType(TokenType.STRING_INTER POLATION_EXPRESSION), expression, TokenFactory.tokenFromType(TokenType.CLOSE_CUR LY_BRACKET));
3437
3438 static InterpolationExpression interpolationExpression2(String identifier) => new InterpolationExpression(TokenFactory.tokenFromType(TokenType.STRING_INTERPOL ATION_IDENTIFIER), identifier3(identifier), null);
3439
3440 static InterpolationString interpolationString(String contents, String value) => new InterpolationString(TokenFactory.tokenFromString(contents), value);
3441
3442 static IsExpression isExpression(Expression expression, bool negated, TypeName type) => new IsExpression(expression, TokenFactory.tokenFromKeyword(Keyword.IS) , negated ? TokenFactory.tokenFromType(TokenType.BANG) : null, type);
3443
3444 static Label label(SimpleIdentifier label) => new Label(label, TokenFactory.to kenFromType(TokenType.COLON));
3445
3446 static Label label2(String label) => AstFactory.label(identifier3(label));
3447
3448 static LabeledStatement labeledStatement(List<Label> labels, Statement stateme nt) => new LabeledStatement(labels, statement);
3449
3450 static LibraryDirective libraryDirective(List<Annotation> metadata, LibraryIde ntifier libraryName) => new LibraryDirective(null, metadata, TokenFactory.tokenF romKeyword(Keyword.LIBRARY), libraryName, TokenFactory.tokenFromType(TokenType.S EMICOLON));
3451
3452 static LibraryDirective libraryDirective2(String libraryName) => libraryDirect ive(new List<Annotation>(), libraryIdentifier2([libraryName]));
3453
3454 static LibraryIdentifier libraryIdentifier(List<SimpleIdentifier> components) => new LibraryIdentifier(list(components));
3455
3456 static LibraryIdentifier libraryIdentifier2(List<String> components) {
3457 List<SimpleIdentifier> componentList = new List<SimpleIdentifier>();
3458 for (String component in components) {
3459 componentList.add(identifier3(component));
3460 }
3461 return new LibraryIdentifier(componentList);
3462 }
3463
3464 static List list(List<Object> elements) {
3465 List elementList = new List();
3466 for (Object element in elements) {
3467 elementList.add(element);
3468 }
3469 return elementList;
3470 }
3471
3472 static ListLiteral listLiteral(List<Expression> elements) => listLiteral2(null , null, elements);
3473
3474 static ListLiteral listLiteral2(Keyword keyword, TypeArgumentList typeArgument s, List<Expression> elements) => new ListLiteral(keyword == null ? null : TokenF actory.tokenFromKeyword(keyword), null, TokenFactory.tokenFromType(TokenType.OPE N_SQUARE_BRACKET), list(elements), TokenFactory.tokenFromType(TokenType.CLOSE_SQ UARE_BRACKET));
3475
3476 static MapLiteral mapLiteral(Keyword keyword, TypeArgumentList typeArguments, List<MapLiteralEntry> entries) => new MapLiteral(keyword == null ? null : TokenF actory.tokenFromKeyword(keyword), typeArguments, TokenFactory.tokenFromType(Toke nType.OPEN_CURLY_BRACKET), list(entries), TokenFactory.tokenFromType(TokenType.C LOSE_CURLY_BRACKET));
3477
3478 static MapLiteral mapLiteral2(List<MapLiteralEntry> entries) => mapLiteral(nul l, null, entries);
3479
3480 static MapLiteralEntry mapLiteralEntry(String key, Expression value) => new Ma pLiteralEntry(string2(key), TokenFactory.tokenFromType(TokenType.COLON), value);
3481
3482 static MethodDeclaration methodDeclaration(Keyword modifier, TypeName returnTy pe, Keyword property, Keyword operator, SimpleIdentifier name, FormalParameterLi st parameters) => new MethodDeclaration(null, null, TokenFactory.tokenFromKeywor d(Keyword.EXTERNAL), modifier == null ? null : TokenFactory.tokenFromKeyword(mod ifier), returnType, property == null ? null : TokenFactory.tokenFromKeyword(prop erty), operator == null ? null : TokenFactory.tokenFromKeyword(operator), name, parameters, emptyFunctionBody());
3483
3484 static MethodDeclaration methodDeclaration2(Keyword modifier, TypeName returnT ype, Keyword property, Keyword operator, SimpleIdentifier name, FormalParameterL ist parameters, FunctionBody body) => new MethodDeclaration(null, null, null, mo difier == null ? null : TokenFactory.tokenFromKeyword(modifier), returnType, pro perty == null ? null : TokenFactory.tokenFromKeyword(property), operator == null ? null : TokenFactory.tokenFromKeyword(operator), name, parameters, body);
3485
3486 static MethodInvocation methodInvocation(Expression target, String methodName, List<Expression> arguments) => new MethodInvocation(target, target == null ? nu ll : TokenFactory.tokenFromType(TokenType.PERIOD), identifier3(methodName), argu mentList(arguments));
3487
3488 static MethodInvocation methodInvocation2(String methodName, List<Expression> arguments) => methodInvocation(null, methodName, arguments);
3489
3490 static NamedExpression namedExpression(Label label, Expression expression) => new NamedExpression(label, expression);
3491
3492 static NamedExpression namedExpression2(String label, Expression expression) = > namedExpression(label2(label), expression);
3493
3494 static DefaultFormalParameter namedFormalParameter(NormalFormalParameter param eter, Expression expression) => new DefaultFormalParameter(parameter, ParameterK ind.NAMED, expression == null ? null : TokenFactory.tokenFromType(TokenType.COLO N), expression);
3495
3496 static NativeClause nativeClause(String nativeCode) => new NativeClause(TokenF actory.tokenFromString("native"), string2(nativeCode));
3497
3498 static NativeFunctionBody nativeFunctionBody(String nativeMethodName) => new N ativeFunctionBody(TokenFactory.tokenFromString("native"), string2(nativeMethodNa me), TokenFactory.tokenFromType(TokenType.SEMICOLON));
3499
3500 static NullLiteral nullLiteral() => new NullLiteral(TokenFactory.tokenFromKeyw ord(Keyword.NULL));
3501
3502 static ParenthesizedExpression parenthesizedExpression(Expression expression) => new ParenthesizedExpression(TokenFactory.tokenFromType(TokenType.OPEN_PAREN), expression, TokenFactory.tokenFromType(TokenType.CLOSE_PAREN));
3503
3504 static PartDirective partDirective(List<Annotation> metadata, String url) => n ew PartDirective(null, metadata, TokenFactory.tokenFromKeyword(Keyword.PART), st ring2(url), TokenFactory.tokenFromType(TokenType.SEMICOLON));
3505
3506 static PartDirective partDirective2(String url) => partDirective(new List<Anno tation>(), url);
3507
3508 static PartOfDirective partOfDirective(LibraryIdentifier libraryName) => partO fDirective2(new List<Annotation>(), libraryName);
3509
3510 static PartOfDirective partOfDirective2(List<Annotation> metadata, LibraryIden tifier libraryName) => new PartOfDirective(null, metadata, TokenFactory.tokenFro mKeyword(Keyword.PART), TokenFactory.tokenFromString("of"), libraryName, TokenFa ctory.tokenFromType(TokenType.SEMICOLON));
3511
3512 static DefaultFormalParameter positionalFormalParameter(NormalFormalParameter parameter, Expression expression) => new DefaultFormalParameter(parameter, Param eterKind.POSITIONAL, expression == null ? null : TokenFactory.tokenFromType(Toke nType.EQ), expression);
3513
3514 static PostfixExpression postfixExpression(Expression expression, TokenType op erator) => new PostfixExpression(expression, TokenFactory.tokenFromType(operator ));
3515
3516 static PrefixExpression prefixExpression(TokenType operator, Expression expres sion) => new PrefixExpression(TokenFactory.tokenFromType(operator), expression);
3517
3518 static PropertyAccess propertyAccess(Expression target, SimpleIdentifier prope rtyName) => new PropertyAccess(target, TokenFactory.tokenFromType(TokenType.PERI OD), propertyName);
3519
3520 static PropertyAccess propertyAccess2(Expression target, String propertyName) => new PropertyAccess(target, TokenFactory.tokenFromType(TokenType.PERIOD), iden tifier3(propertyName));
3521
3522 static RedirectingConstructorInvocation redirectingConstructorInvocation(List< Expression> arguments) => redirectingConstructorInvocation2(null, arguments);
3523
3524 static RedirectingConstructorInvocation redirectingConstructorInvocation2(Stri ng constructorName, List<Expression> arguments) => new RedirectingConstructorInv ocation(TokenFactory.tokenFromKeyword(Keyword.THIS), constructorName == null ? n ull : TokenFactory.tokenFromType(TokenType.PERIOD), constructorName == null ? nu ll : identifier3(constructorName), argumentList(arguments));
3525
3526 static RethrowExpression rethrowExpression() => new RethrowExpression(TokenFac tory.tokenFromKeyword(Keyword.RETHROW));
3527
3528 static ReturnStatement returnStatement() => returnStatement2(null);
3529
3530 static ReturnStatement returnStatement2(Expression expression) => new ReturnSt atement(TokenFactory.tokenFromKeyword(Keyword.RETURN), expression, TokenFactory. tokenFromType(TokenType.SEMICOLON));
3531
3532 static ScriptTag scriptTag(String scriptTag) => new ScriptTag(TokenFactory.tok enFromString(scriptTag));
3533
3534 static ShowCombinator showCombinator(List<SimpleIdentifier> identifiers) => ne w ShowCombinator(TokenFactory.tokenFromString("show"), list(identifiers));
3535
3536 static ShowCombinator showCombinator2(List<String> identifiers) {
3537 List<SimpleIdentifier> identifierList = new List<SimpleIdentifier>();
3538 for (String identifier in identifiers) {
3539 identifierList.add(identifier3(identifier));
3540 }
3541 return new ShowCombinator(TokenFactory.tokenFromString("show"), identifierLi st);
3542 }
3543
3544 static SimpleFormalParameter simpleFormalParameter(Keyword keyword, String par ameterName) => simpleFormalParameter2(keyword, null, parameterName);
3545
3546 static SimpleFormalParameter simpleFormalParameter2(Keyword keyword, TypeName type, String parameterName) => new SimpleFormalParameter(null, null, keyword == null ? null : TokenFactory.tokenFromKeyword(keyword), type, identifier3(paramete rName));
3547
3548 static SimpleFormalParameter simpleFormalParameter3(String parameterName) => s impleFormalParameter2(null, null, parameterName);
3549
3550 static SimpleFormalParameter simpleFormalParameter4(TypeName type, String para meterName) => simpleFormalParameter2(null, type, parameterName);
3551
3552 static StringInterpolation string(List<InterpolationElement> elements) => new StringInterpolation(list(elements));
3553
3554 static SimpleStringLiteral string2(String content) => new SimpleStringLiteral( TokenFactory.tokenFromString("'${content}'"), content);
3555
3556 static SuperConstructorInvocation superConstructorInvocation(List<Expression> arguments) => superConstructorInvocation2(null, arguments);
3557
3558 static SuperConstructorInvocation superConstructorInvocation2(String name, Lis t<Expression> arguments) => new SuperConstructorInvocation(TokenFactory.tokenFro mKeyword(Keyword.SUPER), name == null ? null : TokenFactory.tokenFromType(TokenT ype.PERIOD), name == null ? null : identifier3(name), argumentList(arguments));
3559
3560 static SuperExpression superExpression() => new SuperExpression(TokenFactory.t okenFromKeyword(Keyword.SUPER));
3561
3562 static SwitchCase switchCase(Expression expression, List<Statement> statements ) => switchCase2(new List<Label>(), expression, statements);
3563
3564 static SwitchCase switchCase2(List<Label> labels, Expression expression, List< Statement> statements) => new SwitchCase(labels, TokenFactory.tokenFromKeyword(K eyword.CASE), expression, TokenFactory.tokenFromType(TokenType.COLON), list(stat ements));
3565
3566 static SwitchDefault switchDefault(List<Label> labels, List<Statement> stateme nts) => new SwitchDefault(labels, TokenFactory.tokenFromKeyword(Keyword.DEFAULT) , TokenFactory.tokenFromType(TokenType.COLON), list(statements));
3567
3568 static SwitchDefault switchDefault2(List<Statement> statements) => switchDefau lt(new List<Label>(), statements);
3569
3570 static SwitchStatement switchStatement(Expression expression, List<SwitchMembe r> members) => new SwitchStatement(TokenFactory.tokenFromKeyword(Keyword.SWITCH) , TokenFactory.tokenFromType(TokenType.OPEN_PAREN), expression, TokenFactory.tok enFromType(TokenType.CLOSE_PAREN), TokenFactory.tokenFromType(TokenType.OPEN_CUR LY_BRACKET), list(members), TokenFactory.tokenFromType(TokenType.CLOSE_CURLY_BRA CKET));
3571
3572 static SymbolLiteral symbolLiteral(List<String> components) {
3573 List<Token> identifierList = new List<Token>();
3574 for (String component in components) {
3575 identifierList.add(TokenFactory.tokenFromTypeAndString(TokenType.IDENTIFIE R, component));
3576 }
3577 return new SymbolLiteral(TokenFactory.tokenFromType(TokenType.HASH), new Lis t.from(identifierList));
3578 }
3579
3580 static ThisExpression thisExpression() => new ThisExpression(TokenFactory.toke nFromKeyword(Keyword.THIS));
3581
3582 static ThrowExpression throwExpression() => throwExpression2(null);
3583
3584 static ThrowExpression throwExpression2(Expression expression) => new ThrowExp ression(TokenFactory.tokenFromKeyword(Keyword.THROW), expression);
3585
3586 static TopLevelVariableDeclaration topLevelVariableDeclaration(Keyword keyword , TypeName type, List<VariableDeclaration> variables) => new TopLevelVariableDec laration(null, null, variableDeclarationList(keyword, type, variables), TokenFac tory.tokenFromType(TokenType.SEMICOLON));
3587
3588 static TopLevelVariableDeclaration topLevelVariableDeclaration2(Keyword keywor d, List<VariableDeclaration> variables) => new TopLevelVariableDeclaration(null, null, variableDeclarationList(keyword, null, variables), TokenFactory.tokenFrom Type(TokenType.SEMICOLON));
3589
3590 static TryStatement tryStatement(Block body, Block finallyClause) => tryStatem ent3(body, new List<CatchClause>(), finallyClause);
3591
3592 static TryStatement tryStatement2(Block body, List<CatchClause> catchClauses) => tryStatement3(body, list(catchClauses), null);
3593
3594 static TryStatement tryStatement3(Block body, List<CatchClause> catchClauses, Block finallyClause) => new TryStatement(TokenFactory.tokenFromKeyword(Keyword.T RY), body, catchClauses, finallyClause == null ? null : TokenFactory.tokenFromKe yword(Keyword.FINALLY), finallyClause);
3595
3596 static FunctionTypeAlias typeAlias(TypeName returnType, String name, TypeParam eterList typeParameters, FormalParameterList parameters) => new FunctionTypeAlia s(null, null, TokenFactory.tokenFromKeyword(Keyword.TYPEDEF), returnType, identi fier3(name), typeParameters, parameters, TokenFactory.tokenFromType(TokenType.SE MICOLON));
3597
3598 static TypeArgumentList typeArgumentList(List<TypeName> typeNames) => new Type ArgumentList(TokenFactory.tokenFromType(TokenType.LT), list(typeNames), TokenFac tory.tokenFromType(TokenType.GT));
3599
3600 /**
3601 * Create a type name whose name has been resolved to the given element and wh ose type has been
3602 * resolved to the type of the given element.
3603 *
3604 * <b>Note:</b> This method does not correctly handle class elements that have type parameters.
3605 *
3606 * @param element the element defining the type represented by the type name
3607 * @return the type name that was created
3608 */
3609 static TypeName typeName(ClassElement element, List<TypeName> arguments) {
3610 SimpleIdentifier name = identifier3(element.name);
3611 name.staticElement = element;
3612 TypeName typeName = typeName3(name, arguments);
3613 typeName.type = element.type;
3614 return typeName;
3615 }
3616
3617 static TypeName typeName3(Identifier name, List<TypeName> arguments) {
3618 if (arguments.length == 0) {
3619 return new TypeName(name, null);
3620 }
3621 return new TypeName(name, typeArgumentList(arguments));
3622 }
3623
3624 static TypeName typeName4(String name, List<TypeName> arguments) {
3625 if (arguments.length == 0) {
3626 return new TypeName(identifier3(name), null);
3627 }
3628 return new TypeName(identifier3(name), typeArgumentList(arguments));
3629 }
3630
3631 static TypeParameter typeParameter(String name) => new TypeParameter(null, nul l, identifier3(name), null, null);
3632
3633 static TypeParameter typeParameter2(String name, TypeName bound) => new TypePa rameter(null, null, identifier3(name), TokenFactory.tokenFromKeyword(Keyword.EXT ENDS), bound);
3634
3635 static TypeParameterList typeParameterList(List<String> typeNames) {
3636 List<TypeParameter> typeParameters = new List<TypeParameter>();
3637 for (String typeName in typeNames) {
3638 typeParameters.add(typeParameter(typeName));
3639 }
3640 return new TypeParameterList(TokenFactory.tokenFromType(TokenType.LT), typeP arameters, TokenFactory.tokenFromType(TokenType.GT));
3641 }
3642
3643 static VariableDeclaration variableDeclaration(String name) => new VariableDec laration(null, null, identifier3(name), null, null);
3644
3645 static VariableDeclaration variableDeclaration2(String name, Expression initia lizer) => new VariableDeclaration(null, null, identifier3(name), TokenFactory.to kenFromType(TokenType.EQ), initializer);
3646
3647 static VariableDeclarationList variableDeclarationList(Keyword keyword, TypeNa me type, List<VariableDeclaration> variables) => new VariableDeclarationList(nul l, null, keyword == null ? null : TokenFactory.tokenFromKeyword(keyword), type, list(variables));
3648
3649 static VariableDeclarationList variableDeclarationList2(Keyword keyword, List< VariableDeclaration> variables) => variableDeclarationList(keyword, null, variab les);
3650
3651 static VariableDeclarationStatement variableDeclarationStatement(Keyword keywo rd, TypeName type, List<VariableDeclaration> variables) => new VariableDeclarati onStatement(variableDeclarationList(keyword, type, variables), TokenFactory.toke nFromType(TokenType.SEMICOLON));
3652
3653 static VariableDeclarationStatement variableDeclarationStatement2(Keyword keyw ord, List<VariableDeclaration> variables) => variableDeclarationStatement(keywor d, null, variables);
3654
3655 static WhileStatement whileStatement(Expression condition, Statement body) => new WhileStatement(TokenFactory.tokenFromKeyword(Keyword.WHILE), TokenFactory.to kenFromType(TokenType.OPEN_PAREN), condition, TokenFactory.tokenFromType(TokenTy pe.CLOSE_PAREN), body);
3656
3657 static WithClause withClause(List<TypeName> types) => new WithClause(TokenFact ory.tokenFromKeyword(Keyword.WITH), list(types));
3658 }
3659
3660 class NodeListTest extends EngineTestCase {
3661 void test_add() {
3662 AstNode parent = AstFactory.argumentList([]);
3663 AstNode firstNode = AstFactory.booleanLiteral(true);
3664 AstNode secondNode = AstFactory.booleanLiteral(false);
3665 NodeList<AstNode> list = new NodeList<AstNode>(parent);
3666 list.insert(0, secondNode);
3667 list.insert(0, firstNode);
3668 EngineTestCase.assertSizeOfList(2, list);
3669 JUnitTestCase.assertSame(firstNode, list[0]);
3670 JUnitTestCase.assertSame(secondNode, list[1]);
3671 JUnitTestCase.assertSame(parent, firstNode.parent);
3672 JUnitTestCase.assertSame(parent, secondNode.parent);
3673 AstNode thirdNode = AstFactory.booleanLiteral(false);
3674 list.insert(1, thirdNode);
3675 EngineTestCase.assertSizeOfList(3, list);
3676 JUnitTestCase.assertSame(firstNode, list[0]);
3677 JUnitTestCase.assertSame(thirdNode, list[1]);
3678 JUnitTestCase.assertSame(secondNode, list[2]);
3679 JUnitTestCase.assertSame(parent, firstNode.parent);
3680 JUnitTestCase.assertSame(parent, secondNode.parent);
3681 JUnitTestCase.assertSame(parent, thirdNode.parent);
3682 }
3683
3684 void test_add_negative() {
3685 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
3686 try {
3687 list.insert(-1, AstFactory.booleanLiteral(true));
3688 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
3689 } on RangeError catch (exception) {
3690 }
3691 }
3692
3693 void test_add_tooBig() {
3694 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
3695 try {
3696 list.insert(1, AstFactory.booleanLiteral(true));
3697 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
3698 } on RangeError catch (exception) {
3699 }
3700 }
3701
3702 void test_addAll() {
3703 AstNode parent = AstFactory.argumentList([]);
3704 List<AstNode> firstNodes = new List<AstNode>();
3705 AstNode firstNode = AstFactory.booleanLiteral(true);
3706 AstNode secondNode = AstFactory.booleanLiteral(false);
3707 firstNodes.add(firstNode);
3708 firstNodes.add(secondNode);
3709 NodeList<AstNode> list = new NodeList<AstNode>(parent);
3710 list.addAll(firstNodes);
3711 EngineTestCase.assertSizeOfList(2, list);
3712 JUnitTestCase.assertSame(firstNode, list[0]);
3713 JUnitTestCase.assertSame(secondNode, list[1]);
3714 JUnitTestCase.assertSame(parent, firstNode.parent);
3715 JUnitTestCase.assertSame(parent, secondNode.parent);
3716 List<AstNode> secondNodes = new List<AstNode>();
3717 AstNode thirdNode = AstFactory.booleanLiteral(true);
3718 AstNode fourthNode = AstFactory.booleanLiteral(false);
3719 secondNodes.add(thirdNode);
3720 secondNodes.add(fourthNode);
3721 list.addAll(secondNodes);
3722 EngineTestCase.assertSizeOfList(4, list);
3723 JUnitTestCase.assertSame(firstNode, list[0]);
3724 JUnitTestCase.assertSame(secondNode, list[1]);
3725 JUnitTestCase.assertSame(thirdNode, list[2]);
3726 JUnitTestCase.assertSame(fourthNode, list[3]);
3727 JUnitTestCase.assertSame(parent, firstNode.parent);
3728 JUnitTestCase.assertSame(parent, secondNode.parent);
3729 JUnitTestCase.assertSame(parent, thirdNode.parent);
3730 JUnitTestCase.assertSame(parent, fourthNode.parent);
3731 }
3732
3733 void test_create() {
3734 AstNode owner = AstFactory.argumentList([]);
3735 NodeList<AstNode> list = NodeList.create(owner);
3736 JUnitTestCase.assertNotNull(list);
3737 EngineTestCase.assertSizeOfList(0, list);
3738 JUnitTestCase.assertSame(owner, list.owner);
3739 }
3740
3741 void test_creation() {
3742 AstNode owner = AstFactory.argumentList([]);
3743 NodeList<AstNode> list = new NodeList<AstNode>(owner);
3744 JUnitTestCase.assertNotNull(list);
3745 EngineTestCase.assertSizeOfList(0, list);
3746 JUnitTestCase.assertSame(owner, list.owner);
3747 }
3748
3749 void test_get_negative() {
3750 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
3751 try {
3752 list[-1];
3753 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
3754 } on RangeError catch (exception) {
3755 }
3756 }
3757
3758 void test_get_tooBig() {
3759 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
3760 try {
3761 list[1];
3762 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
3763 } on RangeError catch (exception) {
3764 }
3765 }
3766
3767 void test_getBeginToken_empty() {
3768 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
3769 JUnitTestCase.assertNull(list.beginToken);
3770 }
3771
3772 void test_getBeginToken_nonEmpty() {
3773 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
3774 AstNode node = AstFactory.parenthesizedExpression(AstFactory.booleanLiteral( true));
3775 list.add(node);
3776 JUnitTestCase.assertSame(node.beginToken, list.beginToken);
3777 }
3778
3779 void test_getEndToken_empty() {
3780 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
3781 JUnitTestCase.assertNull(list.endToken);
3782 }
3783
3784 void test_getEndToken_nonEmpty() {
3785 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
3786 AstNode node = AstFactory.parenthesizedExpression(AstFactory.booleanLiteral( true));
3787 list.add(node);
3788 JUnitTestCase.assertSame(node.endToken, list.endToken);
3789 }
3790
3791 void test_indexOf() {
3792 List<AstNode> nodes = new List<AstNode>();
3793 AstNode firstNode = AstFactory.booleanLiteral(true);
3794 AstNode secondNode = AstFactory.booleanLiteral(false);
3795 AstNode thirdNode = AstFactory.booleanLiteral(true);
3796 AstNode fourthNode = AstFactory.booleanLiteral(false);
3797 nodes.add(firstNode);
3798 nodes.add(secondNode);
3799 nodes.add(thirdNode);
3800 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
3801 list.addAll(nodes);
3802 EngineTestCase.assertSizeOfList(3, list);
3803 JUnitTestCase.assertEquals(0, list.indexOf(firstNode));
3804 JUnitTestCase.assertEquals(1, list.indexOf(secondNode));
3805 JUnitTestCase.assertEquals(2, list.indexOf(thirdNode));
3806 JUnitTestCase.assertEquals(-1, list.indexOf(fourthNode));
3807 JUnitTestCase.assertEquals(-1, list.indexOf(null));
3808 }
3809
3810 void test_remove() {
3811 List<AstNode> nodes = new List<AstNode>();
3812 AstNode firstNode = AstFactory.booleanLiteral(true);
3813 AstNode secondNode = AstFactory.booleanLiteral(false);
3814 AstNode thirdNode = AstFactory.booleanLiteral(true);
3815 nodes.add(firstNode);
3816 nodes.add(secondNode);
3817 nodes.add(thirdNode);
3818 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
3819 list.addAll(nodes);
3820 EngineTestCase.assertSizeOfList(3, list);
3821 JUnitTestCase.assertSame(secondNode, list.removeAt(1));
3822 EngineTestCase.assertSizeOfList(2, list);
3823 JUnitTestCase.assertSame(firstNode, list[0]);
3824 JUnitTestCase.assertSame(thirdNode, list[1]);
3825 }
3826
3827 void test_remove_negative() {
3828 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
3829 try {
3830 list.removeAt(-1);
3831 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
3832 } on RangeError catch (exception) {
3833 }
3834 }
3835
3836 void test_remove_tooBig() {
3837 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
3838 try {
3839 list.removeAt(1);
3840 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
3841 } on RangeError catch (exception) {
3842 }
3843 }
3844
3845 void test_set() {
3846 List<AstNode> nodes = new List<AstNode>();
3847 AstNode firstNode = AstFactory.booleanLiteral(true);
3848 AstNode secondNode = AstFactory.booleanLiteral(false);
3849 AstNode thirdNode = AstFactory.booleanLiteral(true);
3850 nodes.add(firstNode);
3851 nodes.add(secondNode);
3852 nodes.add(thirdNode);
3853 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
3854 list.addAll(nodes);
3855 EngineTestCase.assertSizeOfList(3, list);
3856 AstNode fourthNode = AstFactory.integer(0);
3857 JUnitTestCase.assertSame(secondNode, javaListSet(list, 1, fourthNode));
3858 EngineTestCase.assertSizeOfList(3, list);
3859 JUnitTestCase.assertSame(firstNode, list[0]);
3860 JUnitTestCase.assertSame(fourthNode, list[1]);
3861 JUnitTestCase.assertSame(thirdNode, list[2]);
3862 }
3863
3864 void test_set_negative() {
3865 AstNode node = AstFactory.booleanLiteral(true);
3866 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
3867 try {
3868 javaListSet(list, -1, node);
3869 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
3870 } on RangeError catch (exception) {
3871 }
3872 }
3873
3874 void test_set_tooBig() {
3875 AstNode node = AstFactory.booleanLiteral(true);
3876 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
3877 try {
3878 javaListSet(list, 1, node);
3879 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
3880 } on RangeError catch (exception) {
3881 }
3882 }
3883
3884 static dartSuite() {
3885 _ut.group('NodeListTest', () {
3886 _ut.test('test_add', () {
3887 final __test = new NodeListTest();
3888 runJUnitTest(__test, __test.test_add);
3889 });
3890 _ut.test('test_addAll', () {
3891 final __test = new NodeListTest();
3892 runJUnitTest(__test, __test.test_addAll);
3893 });
3894 _ut.test('test_add_negative', () {
3895 final __test = new NodeListTest();
3896 runJUnitTest(__test, __test.test_add_negative);
3897 });
3898 _ut.test('test_add_tooBig', () {
3899 final __test = new NodeListTest();
3900 runJUnitTest(__test, __test.test_add_tooBig);
3901 });
3902 _ut.test('test_create', () {
3903 final __test = new NodeListTest();
3904 runJUnitTest(__test, __test.test_create);
3905 });
3906 _ut.test('test_creation', () {
3907 final __test = new NodeListTest();
3908 runJUnitTest(__test, __test.test_creation);
3909 });
3910 _ut.test('test_getBeginToken_empty', () {
3911 final __test = new NodeListTest();
3912 runJUnitTest(__test, __test.test_getBeginToken_empty);
3913 });
3914 _ut.test('test_getBeginToken_nonEmpty', () {
3915 final __test = new NodeListTest();
3916 runJUnitTest(__test, __test.test_getBeginToken_nonEmpty);
3917 });
3918 _ut.test('test_getEndToken_empty', () {
3919 final __test = new NodeListTest();
3920 runJUnitTest(__test, __test.test_getEndToken_empty);
3921 });
3922 _ut.test('test_getEndToken_nonEmpty', () {
3923 final __test = new NodeListTest();
3924 runJUnitTest(__test, __test.test_getEndToken_nonEmpty);
3925 });
3926 _ut.test('test_get_negative', () {
3927 final __test = new NodeListTest();
3928 runJUnitTest(__test, __test.test_get_negative);
3929 });
3930 _ut.test('test_get_tooBig', () {
3931 final __test = new NodeListTest();
3932 runJUnitTest(__test, __test.test_get_tooBig);
3933 });
3934 _ut.test('test_indexOf', () {
3935 final __test = new NodeListTest();
3936 runJUnitTest(__test, __test.test_indexOf);
3937 });
3938 _ut.test('test_remove', () {
3939 final __test = new NodeListTest();
3940 runJUnitTest(__test, __test.test_remove);
3941 });
3942 _ut.test('test_remove_negative', () {
3943 final __test = new NodeListTest();
3944 runJUnitTest(__test, __test.test_remove_negative);
3945 });
3946 _ut.test('test_remove_tooBig', () {
3947 final __test = new NodeListTest();
3948 runJUnitTest(__test, __test.test_remove_tooBig);
3949 });
3950 _ut.test('test_set', () {
3951 final __test = new NodeListTest();
3952 runJUnitTest(__test, __test.test_set);
3953 });
3954 _ut.test('test_set_negative', () {
3955 final __test = new NodeListTest();
3956 runJUnitTest(__test, __test.test_set_negative);
3957 });
3958 _ut.test('test_set_tooBig', () {
3959 final __test = new NodeListTest();
3960 runJUnitTest(__test, __test.test_set_tooBig);
3961 });
3962 });
3963 }
3964 }
3965
3966 class BreadthFirstVisitorTest extends ParserTestCase {
3967 void testIt() {
3968 String source = EngineTestCase.createSource([
3969 "class A {",
3970 " bool get g => true;",
3971 "}",
3972 "class B {",
3973 " int f() {",
3974 " num q() {",
3975 " return 3;",
3976 " }",
3977 " return q() + 4;",
3978 " }",
3979 "}",
3980 "A f(var p) {",
3981 " if ((p as A).g) {",
3982 " return p;",
3983 " } else {",
3984 " return null;",
3985 " }",
3986 "}"]);
3987 CompilationUnit unit = ParserTestCase.parseCompilationUnit(source, []);
3988 List<AstNode> nodes = new List<AstNode>();
3989 BreadthFirstVisitor<Object> visitor = new BreadthFirstVisitor_BreadthFirstVi sitorTest_testIt(nodes);
3990 visitor.visitAllNodes(unit);
3991 EngineTestCase.assertSizeOfList(59, nodes);
3992 EngineTestCase.assertInstanceOf((obj) => obj is CompilationUnit, Compilation Unit, nodes[0]);
3993 EngineTestCase.assertInstanceOf((obj) => obj is ClassDeclaration, ClassDecla ration, nodes[2]);
3994 EngineTestCase.assertInstanceOf((obj) => obj is FunctionDeclaration, Functio nDeclaration, nodes[3]);
3995 EngineTestCase.assertInstanceOf((obj) => obj is FunctionDeclarationStatement , FunctionDeclarationStatement, nodes[27]);
3996 EngineTestCase.assertInstanceOf((obj) => obj is IntegerLiteral, IntegerLiter al, nodes[58]);
3997 }
3998
3999 static dartSuite() {
4000 _ut.group('BreadthFirstVisitorTest', () {
4001 _ut.test('testIt', () {
4002 final __test = new BreadthFirstVisitorTest();
4003 runJUnitTest(__test, __test.testIt);
4004 });
4005 });
4006 }
4007 }
4008
4009 class BreadthFirstVisitor_BreadthFirstVisitorTest_testIt extends BreadthFirstVis itor<Object> {
4010 List<AstNode> nodes;
4011
4012 BreadthFirstVisitor_BreadthFirstVisitorTest_testIt(this.nodes) : super();
4013
4014 @override
4015 Object visitNode(AstNode node) {
4016 nodes.add(node);
4017 return super.visitNode(node);
4018 }
4019 }
4020
4021 class IndexExpressionTest extends EngineTestCase {
4022 void test_inGetterContext_assignment_compound_left() {
4023 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
4024 // a[i] += ?
4025 AstFactory.assignmentExpression(expression, TokenType.PLUS_EQ, null);
4026 JUnitTestCase.assertTrue(expression.inGetterContext());
4027 }
4028
4029 void test_inGetterContext_assignment_simple_left() {
4030 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
4031 // a[i] = ?
4032 AstFactory.assignmentExpression(expression, TokenType.EQ, null);
4033 JUnitTestCase.assertFalse(expression.inGetterContext());
4034 }
4035
4036 void test_inGetterContext_nonAssignment() {
4037 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
4038 // a[i] + ?
4039 AstFactory.binaryExpression(expression, TokenType.PLUS, null);
4040 JUnitTestCase.assertTrue(expression.inGetterContext());
4041 }
4042
4043 void test_inSetterContext_assignment_compound_left() {
4044 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
4045 // a[i] += ?
4046 AstFactory.assignmentExpression(expression, TokenType.PLUS_EQ, null);
4047 JUnitTestCase.assertTrue(expression.inSetterContext());
4048 }
4049
4050 void test_inSetterContext_assignment_compound_right() {
4051 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
4052 // ? += a[i]
4053 AstFactory.assignmentExpression(null, TokenType.PLUS_EQ, expression);
4054 JUnitTestCase.assertFalse(expression.inSetterContext());
4055 }
4056
4057 void test_inSetterContext_assignment_simple_left() {
4058 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
4059 // a[i] = ?
4060 AstFactory.assignmentExpression(expression, TokenType.EQ, null);
4061 JUnitTestCase.assertTrue(expression.inSetterContext());
4062 }
4063
4064 void test_inSetterContext_assignment_simple_right() {
4065 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
4066 // ? = a[i]
4067 AstFactory.assignmentExpression(null, TokenType.EQ, expression);
4068 JUnitTestCase.assertFalse(expression.inSetterContext());
4069 }
4070
4071 void test_inSetterContext_nonAssignment() {
4072 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
4073 AstFactory.binaryExpression(expression, TokenType.PLUS, null);
4074 // a[i] + ?
4075 JUnitTestCase.assertFalse(expression.inSetterContext());
4076 }
4077
4078 void test_inSetterContext_postfix() {
4079 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
4080 AstFactory.postfixExpression(expression, TokenType.PLUS_PLUS);
4081 // a[i]++
4082 JUnitTestCase.assertTrue(expression.inSetterContext());
4083 }
4084
4085 void test_inSetterContext_prefix_bang() {
4086 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
4087 // !a[i]
4088 AstFactory.prefixExpression(TokenType.BANG, expression);
4089 JUnitTestCase.assertFalse(expression.inSetterContext());
4090 }
4091
4092 void test_inSetterContext_prefix_minusMinus() {
4093 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
4094 // --a[i]
4095 AstFactory.prefixExpression(TokenType.MINUS_MINUS, expression);
4096 JUnitTestCase.assertTrue(expression.inSetterContext());
4097 }
4098
4099 void test_inSetterContext_prefix_plusPlus() {
4100 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
4101 // ++a[i]
4102 AstFactory.prefixExpression(TokenType.PLUS_PLUS, expression);
4103 JUnitTestCase.assertTrue(expression.inSetterContext());
4104 }
4105
4106 static dartSuite() {
4107 _ut.group('IndexExpressionTest', () {
4108 _ut.test('test_inGetterContext_assignment_compound_left', () {
4109 final __test = new IndexExpressionTest();
4110 runJUnitTest(__test, __test.test_inGetterContext_assignment_compound_lef t);
4111 });
4112 _ut.test('test_inGetterContext_assignment_simple_left', () {
4113 final __test = new IndexExpressionTest();
4114 runJUnitTest(__test, __test.test_inGetterContext_assignment_simple_left) ;
4115 });
4116 _ut.test('test_inGetterContext_nonAssignment', () {
4117 final __test = new IndexExpressionTest();
4118 runJUnitTest(__test, __test.test_inGetterContext_nonAssignment);
4119 });
4120 _ut.test('test_inSetterContext_assignment_compound_left', () {
4121 final __test = new IndexExpressionTest();
4122 runJUnitTest(__test, __test.test_inSetterContext_assignment_compound_lef t);
4123 });
4124 _ut.test('test_inSetterContext_assignment_compound_right', () {
4125 final __test = new IndexExpressionTest();
4126 runJUnitTest(__test, __test.test_inSetterContext_assignment_compound_rig ht);
4127 });
4128 _ut.test('test_inSetterContext_assignment_simple_left', () {
4129 final __test = new IndexExpressionTest();
4130 runJUnitTest(__test, __test.test_inSetterContext_assignment_simple_left) ;
4131 });
4132 _ut.test('test_inSetterContext_assignment_simple_right', () {
4133 final __test = new IndexExpressionTest();
4134 runJUnitTest(__test, __test.test_inSetterContext_assignment_simple_right );
4135 });
4136 _ut.test('test_inSetterContext_nonAssignment', () {
4137 final __test = new IndexExpressionTest();
4138 runJUnitTest(__test, __test.test_inSetterContext_nonAssignment);
4139 });
4140 _ut.test('test_inSetterContext_postfix', () {
4141 final __test = new IndexExpressionTest();
4142 runJUnitTest(__test, __test.test_inSetterContext_postfix);
4143 });
4144 _ut.test('test_inSetterContext_prefix_bang', () {
4145 final __test = new IndexExpressionTest();
4146 runJUnitTest(__test, __test.test_inSetterContext_prefix_bang);
4147 });
4148 _ut.test('test_inSetterContext_prefix_minusMinus', () {
4149 final __test = new IndexExpressionTest();
4150 runJUnitTest(__test, __test.test_inSetterContext_prefix_minusMinus);
4151 });
4152 _ut.test('test_inSetterContext_prefix_plusPlus', () {
4153 final __test = new IndexExpressionTest();
4154 runJUnitTest(__test, __test.test_inSetterContext_prefix_plusPlus);
4155 });
4156 });
4157 }
4158 }
4159
4160 class ClassTypeAliasTest extends ParserTestCase {
4161 void test_isAbstract() {
4162 JUnitTestCase.assertFalse(AstFactory.classTypeAlias("A", null, null, null, n ull, null).isAbstract);
4163 JUnitTestCase.assertTrue(AstFactory.classTypeAlias("B", null, Keyword.ABSTRA CT, null, null, null).isAbstract);
4164 }
4165
4166 static dartSuite() {
4167 _ut.group('ClassTypeAliasTest', () {
4168 _ut.test('test_isAbstract', () {
4169 final __test = new ClassTypeAliasTest();
4170 runJUnitTest(__test, __test.test_isAbstract);
4171 });
4172 });
4173 }
4174 }
4175
4176 class ClassDeclarationTest extends ParserTestCase {
4177 void test_getConstructor() {
4178 List<ConstructorInitializer> initializers = new List<ConstructorInitializer> ();
4179 ConstructorDeclaration defaultConstructor = AstFactory.constructorDeclaratio n(AstFactory.identifier3("Test"), null, AstFactory.formalParameterList([]), init ializers);
4180 ConstructorDeclaration aConstructor = AstFactory.constructorDeclaration(AstF actory.identifier3("Test"), "a", AstFactory.formalParameterList([]), initializer s);
4181 ConstructorDeclaration bConstructor = AstFactory.constructorDeclaration(AstF actory.identifier3("Test"), "b", AstFactory.formalParameterList([]), initializer s);
4182 ClassDeclaration clazz = AstFactory.classDeclaration(null, "Test", null, nul l, null, null, [defaultConstructor, aConstructor, bConstructor]);
4183 JUnitTestCase.assertSame(defaultConstructor, clazz.getConstructor(null));
4184 JUnitTestCase.assertSame(aConstructor, clazz.getConstructor("a"));
4185 JUnitTestCase.assertSame(bConstructor, clazz.getConstructor("b"));
4186 JUnitTestCase.assertSame(null, clazz.getConstructor("noSuchConstructor"));
4187 }
4188
4189 void test_getField() {
4190 VariableDeclaration aVar = AstFactory.variableDeclaration("a");
4191 VariableDeclaration bVar = AstFactory.variableDeclaration("b");
4192 VariableDeclaration cVar = AstFactory.variableDeclaration("c");
4193 ClassDeclaration clazz = AstFactory.classDeclaration(null, "Test", null, nul l, null, null, [
4194 AstFactory.fieldDeclaration2(false, null, [aVar]),
4195 AstFactory.fieldDeclaration2(false, null, [bVar, cVar])]);
4196 JUnitTestCase.assertSame(aVar, clazz.getField("a"));
4197 JUnitTestCase.assertSame(bVar, clazz.getField("b"));
4198 JUnitTestCase.assertSame(cVar, clazz.getField("c"));
4199 JUnitTestCase.assertSame(null, clazz.getField("noSuchField"));
4200 }
4201
4202 void test_getMethod() {
4203 MethodDeclaration aMethod = AstFactory.methodDeclaration(null, null, null, n ull, AstFactory.identifier3("a"), AstFactory.formalParameterList([]));
4204 MethodDeclaration bMethod = AstFactory.methodDeclaration(null, null, null, n ull, AstFactory.identifier3("b"), AstFactory.formalParameterList([]));
4205 ClassDeclaration clazz = AstFactory.classDeclaration(null, "Test", null, nul l, null, null, [aMethod, bMethod]);
4206 JUnitTestCase.assertSame(aMethod, clazz.getMethod("a"));
4207 JUnitTestCase.assertSame(bMethod, clazz.getMethod("b"));
4208 JUnitTestCase.assertSame(null, clazz.getMethod("noSuchMethod"));
4209 }
4210
4211 void test_isAbstract() {
4212 JUnitTestCase.assertFalse(AstFactory.classDeclaration(null, "A", null, null, null, null, []).isAbstract);
4213 JUnitTestCase.assertTrue(AstFactory.classDeclaration(Keyword.ABSTRACT, "B", null, null, null, null, []).isAbstract);
4214 }
4215
4216 static dartSuite() {
4217 _ut.group('ClassDeclarationTest', () {
4218 _ut.test('test_getConstructor', () {
4219 final __test = new ClassDeclarationTest();
4220 runJUnitTest(__test, __test.test_getConstructor);
4221 });
4222 _ut.test('test_getField', () {
4223 final __test = new ClassDeclarationTest();
4224 runJUnitTest(__test, __test.test_getField);
4225 });
4226 _ut.test('test_getMethod', () {
4227 final __test = new ClassDeclarationTest();
4228 runJUnitTest(__test, __test.test_getMethod);
4229 });
4230 _ut.test('test_isAbstract', () {
4231 final __test = new ClassDeclarationTest();
4232 runJUnitTest(__test, __test.test_isAbstract);
4233 });
4234 });
4235 }
4236 }
4237
4238 class VariableDeclarationTest extends ParserTestCase {
4239 void test_getDocumentationComment_onGrandParent() {
4240 VariableDeclaration varDecl = AstFactory.variableDeclaration("a");
4241 TopLevelVariableDeclaration decl = AstFactory.topLevelVariableDeclaration2(K eyword.VAR, [varDecl]);
4242 Comment comment = Comment.createDocumentationComment(new List<Token>(0));
4243 JUnitTestCase.assertNull(varDecl.documentationComment);
4244 decl.documentationComment = comment;
4245 JUnitTestCase.assertNotNull(varDecl.documentationComment);
4246 JUnitTestCase.assertNotNull(decl.documentationComment);
4247 }
4248
4249 void test_getDocumentationComment_onNode() {
4250 VariableDeclaration decl = AstFactory.variableDeclaration("a");
4251 Comment comment = Comment.createDocumentationComment(new List<Token>(0));
4252 decl.documentationComment = comment;
4253 JUnitTestCase.assertNotNull(decl.documentationComment);
4254 }
4255
4256 static dartSuite() {
4257 _ut.group('VariableDeclarationTest', () {
4258 _ut.test('test_getDocumentationComment_onGrandParent', () {
4259 final __test = new VariableDeclarationTest();
4260 runJUnitTest(__test, __test.test_getDocumentationComment_onGrandParent);
4261 });
4262 _ut.test('test_getDocumentationComment_onNode', () {
4263 final __test = new VariableDeclarationTest();
4264 runJUnitTest(__test, __test.test_getDocumentationComment_onNode);
4265 });
4266 });
4267 }
4268 } 4268 }
4269 4269
4270 main() { 4270 main() {
4271 ConstantEvaluatorTest.dartSuite(); 4271 ConstantEvaluatorTest.dartSuite();
4272 NodeLocatorTest.dartSuite(); 4272 NodeLocatorTest.dartSuite();
4273 ToSourceVisitorTest.dartSuite(); 4273 ToSourceVisitorTest.dartSuite();
4274 BreadthFirstVisitorTest.dartSuite(); 4274 BreadthFirstVisitorTest.dartSuite();
4275 ClassDeclarationTest.dartSuite(); 4275 ClassDeclarationTest.dartSuite();
4276 ClassTypeAliasTest.dartSuite(); 4276 ClassTypeAliasTest.dartSuite();
4277 IndexExpressionTest.dartSuite(); 4277 IndexExpressionTest.dartSuite();
4278 NodeListTest.dartSuite(); 4278 NodeListTest.dartSuite();
4279 SimpleIdentifierTest.dartSuite(); 4279 SimpleIdentifierTest.dartSuite();
4280 SimpleStringLiteralTest.dartSuite(); 4280 SimpleStringLiteralTest.dartSuite();
4281 VariableDeclarationTest.dartSuite(); 4281 VariableDeclarationTest.dartSuite();
4282 } 4282 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698