OLD | NEW |
| (Empty) |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library analyzer.src.generated.testing.ast_factory; | |
6 | |
7 import 'package:analyzer/dart/ast/ast.dart'; | |
8 import 'package:analyzer/dart/ast/token.dart'; | |
9 import 'package:analyzer/dart/element/element.dart'; | |
10 import 'package:analyzer/src/dart/ast/ast.dart'; | |
11 import 'package:analyzer/src/generated/testing/token_factory.dart'; | |
12 import 'package:analyzer/src/generated/utilities_dart.dart'; | |
13 | |
14 /** | |
15 * The class `AstFactory` defines utility methods that can be used to create AST
nodes. The | |
16 * nodes that are created are complete in the sense that all of the tokens that
would have been | |
17 * associated with the nodes by a parser are also created, but the token stream
is not constructed. | |
18 * None of the nodes are resolved. | |
19 * | |
20 * The general pattern is for the name of the factory method to be the same as t
he name of the class | |
21 * of AST node being created. There are two notable exceptions. The first is for
methods creating | |
22 * nodes that are part of a cascade expression. These methods are all prefixed w
ith 'cascaded'. The | |
23 * second is places where a shorter name seemed unambiguous and easier to read,
such as using | |
24 * 'identifier' rather than 'prefixedIdentifier', or 'integer' rather than 'inte
gerLiteral'. | |
25 */ | |
26 class AstFactory { | |
27 static AdjacentStrings adjacentStrings(List<StringLiteral> strings) => | |
28 new AdjacentStrings(strings); | |
29 | |
30 static Annotation annotation(Identifier name) => new Annotation( | |
31 TokenFactory.tokenFromType(TokenType.AT), name, null, null, null); | |
32 | |
33 static Annotation annotation2(Identifier name, | |
34 SimpleIdentifier constructorName, ArgumentList arguments) => | |
35 new Annotation( | |
36 TokenFactory.tokenFromType(TokenType.AT), | |
37 name, | |
38 constructorName == null | |
39 ? null | |
40 : TokenFactory.tokenFromType(TokenType.PERIOD), | |
41 constructorName, | |
42 arguments); | |
43 | |
44 static ArgumentList argumentList([List<Expression> arguments]) => | |
45 new ArgumentList(TokenFactory.tokenFromType(TokenType.OPEN_PAREN), | |
46 arguments, TokenFactory.tokenFromType(TokenType.CLOSE_PAREN)); | |
47 | |
48 static AsExpression asExpression(Expression expression, TypeName type) => | |
49 new AsExpression( | |
50 expression, TokenFactory.tokenFromKeyword(Keyword.AS), type); | |
51 | |
52 static AssertStatement assertStatement(Expression condition, | |
53 [Expression message]) => | |
54 new AssertStatement( | |
55 TokenFactory.tokenFromKeyword(Keyword.ASSERT), | |
56 TokenFactory.tokenFromType(TokenType.OPEN_PAREN), | |
57 condition, | |
58 message == null ? null : TokenFactory.tokenFromType(TokenType.COMMA), | |
59 message, | |
60 TokenFactory.tokenFromType(TokenType.CLOSE_PAREN), | |
61 TokenFactory.tokenFromType(TokenType.SEMICOLON)); | |
62 | |
63 static AssignmentExpression assignmentExpression(Expression leftHandSide, | |
64 TokenType operator, Expression rightHandSide) => | |
65 new AssignmentExpression( | |
66 leftHandSide, TokenFactory.tokenFromType(operator), rightHandSide); | |
67 | |
68 static BlockFunctionBody asyncBlockFunctionBody( | |
69 [List<Statement> statements]) => | |
70 new BlockFunctionBody( | |
71 TokenFactory.tokenFromTypeAndString(TokenType.IDENTIFIER, "async"), | |
72 null, | |
73 block(statements)); | |
74 | |
75 static ExpressionFunctionBody asyncExpressionFunctionBody( | |
76 Expression expression) => | |
77 new ExpressionFunctionBody( | |
78 TokenFactory.tokenFromTypeAndString(TokenType.IDENTIFIER, "async"), | |
79 TokenFactory.tokenFromType(TokenType.FUNCTION), | |
80 expression, | |
81 TokenFactory.tokenFromType(TokenType.SEMICOLON)); | |
82 | |
83 static BlockFunctionBody asyncGeneratorBlockFunctionBody( | |
84 [List<Statement> statements]) => | |
85 new BlockFunctionBody( | |
86 TokenFactory.tokenFromTypeAndString(TokenType.IDENTIFIER, "async"), | |
87 TokenFactory.tokenFromType(TokenType.STAR), | |
88 block(statements)); | |
89 | |
90 static AwaitExpression awaitExpression(Expression expression) => | |
91 new AwaitExpression( | |
92 TokenFactory.tokenFromTypeAndString(TokenType.IDENTIFIER, "await"), | |
93 expression); | |
94 | |
95 static BinaryExpression binaryExpression(Expression leftOperand, | |
96 TokenType operator, Expression rightOperand) => | |
97 new BinaryExpression( | |
98 leftOperand, TokenFactory.tokenFromType(operator), rightOperand); | |
99 | |
100 static Block block([List<Statement> statements]) => new Block( | |
101 TokenFactory.tokenFromType(TokenType.OPEN_CURLY_BRACKET), | |
102 statements, | |
103 TokenFactory.tokenFromType(TokenType.CLOSE_CURLY_BRACKET)); | |
104 | |
105 static BlockFunctionBody blockFunctionBody(Block block) => | |
106 new BlockFunctionBody(null, null, block); | |
107 | |
108 static BlockFunctionBody blockFunctionBody2([List<Statement> statements]) => | |
109 new BlockFunctionBody(null, null, block(statements)); | |
110 | |
111 static BooleanLiteral booleanLiteral(bool value) => new BooleanLiteral( | |
112 value | |
113 ? TokenFactory.tokenFromKeyword(Keyword.TRUE) | |
114 : TokenFactory.tokenFromKeyword(Keyword.FALSE), | |
115 value); | |
116 | |
117 static BreakStatement breakStatement() => new BreakStatement( | |
118 TokenFactory.tokenFromKeyword(Keyword.BREAK), | |
119 null, | |
120 TokenFactory.tokenFromType(TokenType.SEMICOLON)); | |
121 | |
122 static BreakStatement breakStatement2(String label) => new BreakStatement( | |
123 TokenFactory.tokenFromKeyword(Keyword.BREAK), | |
124 identifier3(label), | |
125 TokenFactory.tokenFromType(TokenType.SEMICOLON)); | |
126 | |
127 static IndexExpression cascadedIndexExpression(Expression index) => | |
128 new IndexExpression.forCascade( | |
129 TokenFactory.tokenFromType(TokenType.PERIOD_PERIOD), | |
130 TokenFactory.tokenFromType(TokenType.OPEN_SQUARE_BRACKET), | |
131 index, | |
132 TokenFactory.tokenFromType(TokenType.CLOSE_SQUARE_BRACKET)); | |
133 | |
134 static MethodInvocation cascadedMethodInvocation(String methodName, | |
135 [List<Expression> arguments]) => | |
136 new MethodInvocation( | |
137 null, | |
138 TokenFactory.tokenFromType(TokenType.PERIOD_PERIOD), | |
139 identifier3(methodName), | |
140 null, | |
141 argumentList(arguments)); | |
142 | |
143 static PropertyAccess cascadedPropertyAccess(String propertyName) => | |
144 new PropertyAccess( | |
145 null, | |
146 TokenFactory.tokenFromType(TokenType.PERIOD_PERIOD), | |
147 identifier3(propertyName)); | |
148 | |
149 static CascadeExpression cascadeExpression(Expression target, | |
150 [List<Expression> cascadeSections]) => | |
151 new CascadeExpression(target, cascadeSections); | |
152 | |
153 static CatchClause catchClause(String exceptionParameter, | |
154 [List<Statement> statements]) => | |
155 catchClause5(null, exceptionParameter, null, statements); | |
156 | |
157 static CatchClause catchClause2( | |
158 String exceptionParameter, String stackTraceParameter, | |
159 [List<Statement> statements]) => | |
160 catchClause5(null, exceptionParameter, stackTraceParameter, statements); | |
161 | |
162 static CatchClause catchClause3(TypeName exceptionType, | |
163 [List<Statement> statements]) => | |
164 catchClause5(exceptionType, null, null, statements); | |
165 | |
166 static CatchClause catchClause4( | |
167 TypeName exceptionType, String exceptionParameter, | |
168 [List<Statement> statements]) => | |
169 catchClause5(exceptionType, exceptionParameter, null, statements); | |
170 | |
171 static CatchClause catchClause5(TypeName exceptionType, | |
172 String exceptionParameter, String stackTraceParameter, | |
173 [List<Statement> statements]) => | |
174 new CatchClause( | |
175 exceptionType == null | |
176 ? null | |
177 : TokenFactory.tokenFromTypeAndString(TokenType.IDENTIFIER, "on"), | |
178 exceptionType, | |
179 exceptionParameter == null | |
180 ? null | |
181 : TokenFactory.tokenFromKeyword(Keyword.CATCH), | |
182 exceptionParameter == null | |
183 ? null | |
184 : TokenFactory.tokenFromType(TokenType.OPEN_PAREN), | |
185 exceptionParameter == null ? null : identifier3(exceptionParameter), | |
186 stackTraceParameter == null | |
187 ? null | |
188 : TokenFactory.tokenFromType(TokenType.COMMA), | |
189 stackTraceParameter == null ? null : identifier3(stackTraceParameter), | |
190 exceptionParameter == null | |
191 ? null | |
192 : TokenFactory.tokenFromType(TokenType.CLOSE_PAREN), | |
193 block(statements)); | |
194 | |
195 static ClassDeclaration classDeclaration( | |
196 Keyword abstractKeyword, | |
197 String name, | |
198 TypeParameterList typeParameters, | |
199 ExtendsClause extendsClause, | |
200 WithClause withClause, | |
201 ImplementsClause implementsClause, | |
202 [List<ClassMember> members]) => | |
203 new ClassDeclaration( | |
204 null, | |
205 null, | |
206 abstractKeyword == null | |
207 ? null | |
208 : TokenFactory.tokenFromKeyword(abstractKeyword), | |
209 TokenFactory.tokenFromKeyword(Keyword.CLASS), | |
210 identifier3(name), | |
211 typeParameters, | |
212 extendsClause, | |
213 withClause, | |
214 implementsClause, | |
215 TokenFactory.tokenFromType(TokenType.OPEN_CURLY_BRACKET), | |
216 members, | |
217 TokenFactory.tokenFromType(TokenType.CLOSE_CURLY_BRACKET)); | |
218 | |
219 static ClassTypeAlias classTypeAlias( | |
220 String name, | |
221 TypeParameterList typeParameters, | |
222 Keyword abstractKeyword, | |
223 TypeName superclass, | |
224 WithClause withClause, | |
225 ImplementsClause implementsClause) => | |
226 new ClassTypeAlias( | |
227 null, | |
228 null, | |
229 TokenFactory.tokenFromKeyword(Keyword.CLASS), | |
230 identifier3(name), | |
231 typeParameters, | |
232 TokenFactory.tokenFromType(TokenType.EQ), | |
233 abstractKeyword == null | |
234 ? null | |
235 : TokenFactory.tokenFromKeyword(abstractKeyword), | |
236 superclass, | |
237 withClause, | |
238 implementsClause, | |
239 TokenFactory.tokenFromType(TokenType.SEMICOLON)); | |
240 | |
241 static CompilationUnit compilationUnit() => | |
242 compilationUnit8(null, null, null); | |
243 | |
244 static CompilationUnit compilationUnit2( | |
245 List<CompilationUnitMember> declarations) => | |
246 compilationUnit8(null, null, declarations); | |
247 | |
248 static CompilationUnit compilationUnit3(List<Directive> directives) => | |
249 compilationUnit8(null, directives, null); | |
250 | |
251 static CompilationUnit compilationUnit4(List<Directive> directives, | |
252 List<CompilationUnitMember> declarations) => | |
253 compilationUnit8(null, directives, declarations); | |
254 | |
255 static CompilationUnit compilationUnit5(String scriptTag) => | |
256 compilationUnit8(scriptTag, null, null); | |
257 | |
258 static CompilationUnit compilationUnit6( | |
259 String scriptTag, List<CompilationUnitMember> declarations) => | |
260 compilationUnit8(scriptTag, null, declarations); | |
261 | |
262 static CompilationUnit compilationUnit7( | |
263 String scriptTag, List<Directive> directives) => | |
264 compilationUnit8(scriptTag, directives, null); | |
265 | |
266 static CompilationUnit compilationUnit8( | |
267 String scriptTag, | |
268 List<Directive> directives, | |
269 List<CompilationUnitMember> declarations) => | |
270 new CompilationUnit( | |
271 TokenFactory.tokenFromType(TokenType.EOF), | |
272 scriptTag == null ? null : AstFactory.scriptTag(scriptTag), | |
273 directives == null ? new List<Directive>() : directives, | |
274 declarations == null | |
275 ? new List<CompilationUnitMember>() | |
276 : declarations, | |
277 TokenFactory.tokenFromType(TokenType.EOF)); | |
278 | |
279 static ConditionalExpression conditionalExpression(Expression condition, | |
280 Expression thenExpression, Expression elseExpression) => | |
281 new ConditionalExpression( | |
282 condition, | |
283 TokenFactory.tokenFromType(TokenType.QUESTION), | |
284 thenExpression, | |
285 TokenFactory.tokenFromType(TokenType.COLON), | |
286 elseExpression); | |
287 | |
288 static ConstructorDeclaration constructorDeclaration( | |
289 Identifier returnType, | |
290 String name, | |
291 FormalParameterList parameters, | |
292 List<ConstructorInitializer> initializers) => | |
293 new ConstructorDeclaration( | |
294 null, | |
295 null, | |
296 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL), | |
297 null, | |
298 null, | |
299 returnType, | |
300 name == null ? null : TokenFactory.tokenFromType(TokenType.PERIOD), | |
301 name == null ? null : identifier3(name), | |
302 parameters, | |
303 initializers == null || initializers.isEmpty | |
304 ? null | |
305 : TokenFactory.tokenFromType(TokenType.PERIOD), | |
306 initializers == null | |
307 ? new List<ConstructorInitializer>() | |
308 : initializers, | |
309 null, | |
310 emptyFunctionBody()); | |
311 | |
312 static ConstructorDeclaration constructorDeclaration2( | |
313 Keyword constKeyword, | |
314 Keyword factoryKeyword, | |
315 Identifier returnType, | |
316 String name, | |
317 FormalParameterList parameters, | |
318 List<ConstructorInitializer> initializers, | |
319 FunctionBody body) => | |
320 new ConstructorDeclaration( | |
321 null, | |
322 null, | |
323 null, | |
324 constKeyword == null | |
325 ? null | |
326 : TokenFactory.tokenFromKeyword(constKeyword), | |
327 factoryKeyword == null | |
328 ? null | |
329 : TokenFactory.tokenFromKeyword(factoryKeyword), | |
330 returnType, | |
331 name == null ? null : TokenFactory.tokenFromType(TokenType.PERIOD), | |
332 name == null ? null : identifier3(name), | |
333 parameters, | |
334 initializers == null || initializers.isEmpty | |
335 ? null | |
336 : TokenFactory.tokenFromType(TokenType.PERIOD), | |
337 initializers == null | |
338 ? new List<ConstructorInitializer>() | |
339 : initializers, | |
340 null, | |
341 body); | |
342 | |
343 static ConstructorFieldInitializer constructorFieldInitializer( | |
344 bool prefixedWithThis, String fieldName, Expression expression) => | |
345 new ConstructorFieldInitializer( | |
346 prefixedWithThis ? TokenFactory.tokenFromKeyword(Keyword.THIS) : null, | |
347 prefixedWithThis | |
348 ? TokenFactory.tokenFromType(TokenType.PERIOD) | |
349 : null, | |
350 identifier3(fieldName), | |
351 TokenFactory.tokenFromType(TokenType.EQ), | |
352 expression); | |
353 | |
354 static ConstructorName constructorName(TypeName type, String name) => | |
355 new ConstructorName( | |
356 type, | |
357 name == null ? null : TokenFactory.tokenFromType(TokenType.PERIOD), | |
358 name == null ? null : identifier3(name)); | |
359 | |
360 static ContinueStatement continueStatement([String label]) => | |
361 new ContinueStatement( | |
362 TokenFactory.tokenFromKeyword(Keyword.CONTINUE), | |
363 label == null ? null : identifier3(label), | |
364 TokenFactory.tokenFromType(TokenType.SEMICOLON)); | |
365 | |
366 static DeclaredIdentifier declaredIdentifier( | |
367 Keyword keyword, String identifier) => | |
368 declaredIdentifier2(keyword, null, identifier); | |
369 | |
370 static DeclaredIdentifier declaredIdentifier2( | |
371 Keyword keyword, TypeName type, String identifier) => | |
372 new DeclaredIdentifier( | |
373 null, | |
374 null, | |
375 keyword == null ? null : TokenFactory.tokenFromKeyword(keyword), | |
376 type, | |
377 identifier3(identifier)); | |
378 | |
379 static DeclaredIdentifier declaredIdentifier3(String identifier) => | |
380 declaredIdentifier2(Keyword.VAR, null, identifier); | |
381 | |
382 static DeclaredIdentifier declaredIdentifier4( | |
383 TypeName type, String identifier) => | |
384 declaredIdentifier2(null, type, identifier); | |
385 | |
386 static Comment documentationComment( | |
387 List<Token> tokens, List<CommentReference> references) { | |
388 return new Comment(tokens, CommentType.DOCUMENTATION, references); | |
389 } | |
390 | |
391 static DoStatement doStatement(Statement body, Expression condition) => | |
392 new DoStatement( | |
393 TokenFactory.tokenFromKeyword(Keyword.DO), | |
394 body, | |
395 TokenFactory.tokenFromKeyword(Keyword.WHILE), | |
396 TokenFactory.tokenFromType(TokenType.OPEN_PAREN), | |
397 condition, | |
398 TokenFactory.tokenFromType(TokenType.CLOSE_PAREN), | |
399 TokenFactory.tokenFromType(TokenType.SEMICOLON)); | |
400 | |
401 static DoubleLiteral doubleLiteral(double value) => | |
402 new DoubleLiteral(TokenFactory.tokenFromString(value.toString()), value); | |
403 | |
404 static EmptyFunctionBody emptyFunctionBody() => | |
405 new EmptyFunctionBody(TokenFactory.tokenFromType(TokenType.SEMICOLON)); | |
406 | |
407 static EmptyStatement emptyStatement() => | |
408 new EmptyStatement(TokenFactory.tokenFromType(TokenType.SEMICOLON)); | |
409 | |
410 static EnumDeclaration enumDeclaration( | |
411 SimpleIdentifier name, List<EnumConstantDeclaration> constants) => | |
412 new EnumDeclaration( | |
413 null, | |
414 null, | |
415 TokenFactory.tokenFromKeyword(Keyword.ENUM), | |
416 name, | |
417 TokenFactory.tokenFromType(TokenType.OPEN_CURLY_BRACKET), | |
418 constants, | |
419 TokenFactory.tokenFromType(TokenType.CLOSE_CURLY_BRACKET)); | |
420 | |
421 static EnumDeclaration enumDeclaration2( | |
422 String name, List<String> constantNames) { | |
423 int count = constantNames.length; | |
424 List<EnumConstantDeclaration> constants = | |
425 new List<EnumConstantDeclaration>(count); | |
426 for (int i = 0; i < count; i++) { | |
427 constants[i] = new EnumConstantDeclaration( | |
428 null, null, identifier3(constantNames[i])); | |
429 } | |
430 return enumDeclaration(identifier3(name), constants); | |
431 } | |
432 | |
433 static ExportDirective exportDirective(List<Annotation> metadata, String uri, | |
434 [List<Combinator> combinators]) => | |
435 new ExportDirective( | |
436 null, | |
437 metadata, | |
438 TokenFactory.tokenFromKeyword(Keyword.EXPORT), | |
439 string2(uri), | |
440 null, | |
441 combinators, | |
442 TokenFactory.tokenFromType(TokenType.SEMICOLON)); | |
443 | |
444 static ExportDirective exportDirective2(String uri, | |
445 [List<Combinator> combinators]) => | |
446 exportDirective(null, uri, combinators); | |
447 | |
448 static ExpressionFunctionBody expressionFunctionBody(Expression expression) => | |
449 new ExpressionFunctionBody( | |
450 null, | |
451 TokenFactory.tokenFromType(TokenType.FUNCTION), | |
452 expression, | |
453 TokenFactory.tokenFromType(TokenType.SEMICOLON)); | |
454 | |
455 static ExpressionStatement expressionStatement(Expression expression) => | |
456 new ExpressionStatement( | |
457 expression, TokenFactory.tokenFromType(TokenType.SEMICOLON)); | |
458 | |
459 static ExtendsClause extendsClause(TypeName type) => | |
460 new ExtendsClause(TokenFactory.tokenFromKeyword(Keyword.EXTENDS), type); | |
461 | |
462 static FieldDeclaration fieldDeclaration(bool isStatic, Keyword keyword, | |
463 TypeName type, List<VariableDeclaration> variables) => | |
464 new FieldDeclaration( | |
465 null, | |
466 null, | |
467 isStatic ? TokenFactory.tokenFromKeyword(Keyword.STATIC) : null, | |
468 variableDeclarationList(keyword, type, variables), | |
469 TokenFactory.tokenFromType(TokenType.SEMICOLON)); | |
470 | |
471 static FieldDeclaration fieldDeclaration2(bool isStatic, Keyword keyword, | |
472 List<VariableDeclaration> variables) => | |
473 fieldDeclaration(isStatic, keyword, null, variables); | |
474 | |
475 static FieldFormalParameter fieldFormalParameter( | |
476 Keyword keyword, TypeName type, String identifier, | |
477 [FormalParameterList parameterList]) => | |
478 new FieldFormalParameter( | |
479 null, | |
480 null, | |
481 keyword == null ? null : TokenFactory.tokenFromKeyword(keyword), | |
482 type, | |
483 TokenFactory.tokenFromKeyword(Keyword.THIS), | |
484 TokenFactory.tokenFromType(TokenType.PERIOD), | |
485 identifier3(identifier), | |
486 null, | |
487 parameterList); | |
488 | |
489 static FieldFormalParameter fieldFormalParameter2(String identifier) => | |
490 fieldFormalParameter(null, null, identifier); | |
491 | |
492 static ForEachStatement forEachStatement(DeclaredIdentifier loopVariable, | |
493 Expression iterator, Statement body) => | |
494 new ForEachStatement.withDeclaration( | |
495 null, | |
496 TokenFactory.tokenFromKeyword(Keyword.FOR), | |
497 TokenFactory.tokenFromType(TokenType.OPEN_PAREN), | |
498 loopVariable, | |
499 TokenFactory.tokenFromKeyword(Keyword.IN), | |
500 iterator, | |
501 TokenFactory.tokenFromType(TokenType.CLOSE_PAREN), | |
502 body); | |
503 | |
504 static ForEachStatement forEachStatement2( | |
505 SimpleIdentifier identifier, Expression iterator, Statement body) => | |
506 new ForEachStatement.withReference( | |
507 null, | |
508 TokenFactory.tokenFromKeyword(Keyword.FOR), | |
509 TokenFactory.tokenFromType(TokenType.OPEN_PAREN), | |
510 identifier, | |
511 TokenFactory.tokenFromKeyword(Keyword.IN), | |
512 iterator, | |
513 TokenFactory.tokenFromType(TokenType.CLOSE_PAREN), | |
514 body); | |
515 | |
516 static FormalParameterList formalParameterList( | |
517 [List<FormalParameter> parameters]) => | |
518 new FormalParameterList( | |
519 TokenFactory.tokenFromType(TokenType.OPEN_PAREN), | |
520 parameters, | |
521 null, | |
522 null, | |
523 TokenFactory.tokenFromType(TokenType.CLOSE_PAREN)); | |
524 | |
525 static ForStatement forStatement(Expression initialization, | |
526 Expression condition, List<Expression> updaters, Statement body) => | |
527 new ForStatement( | |
528 TokenFactory.tokenFromKeyword(Keyword.FOR), | |
529 TokenFactory.tokenFromType(TokenType.OPEN_PAREN), | |
530 null, | |
531 initialization, | |
532 TokenFactory.tokenFromType(TokenType.SEMICOLON), | |
533 condition, | |
534 TokenFactory.tokenFromType(TokenType.SEMICOLON), | |
535 updaters, | |
536 TokenFactory.tokenFromType(TokenType.CLOSE_PAREN), | |
537 body); | |
538 | |
539 static ForStatement forStatement2(VariableDeclarationList variableList, | |
540 Expression condition, List<Expression> updaters, Statement body) => | |
541 new ForStatement( | |
542 TokenFactory.tokenFromKeyword(Keyword.FOR), | |
543 TokenFactory.tokenFromType(TokenType.OPEN_PAREN), | |
544 variableList, | |
545 null, | |
546 TokenFactory.tokenFromType(TokenType.SEMICOLON), | |
547 condition, | |
548 TokenFactory.tokenFromType(TokenType.SEMICOLON), | |
549 updaters, | |
550 TokenFactory.tokenFromType(TokenType.CLOSE_PAREN), | |
551 body); | |
552 | |
553 static FunctionDeclaration functionDeclaration(TypeName type, Keyword keyword, | |
554 String name, FunctionExpression functionExpression) => | |
555 new FunctionDeclaration( | |
556 null, | |
557 null, | |
558 null, | |
559 type, | |
560 keyword == null ? null : TokenFactory.tokenFromKeyword(keyword), | |
561 identifier3(name), | |
562 functionExpression); | |
563 | |
564 static FunctionDeclarationStatement functionDeclarationStatement( | |
565 TypeName type, | |
566 Keyword keyword, | |
567 String name, | |
568 FunctionExpression functionExpression) => | |
569 new FunctionDeclarationStatement( | |
570 functionDeclaration(type, keyword, name, functionExpression)); | |
571 | |
572 static FunctionExpression functionExpression() => | |
573 new FunctionExpression(null, formalParameterList(), blockFunctionBody2()); | |
574 | |
575 static FunctionExpression functionExpression2( | |
576 FormalParameterList parameters, FunctionBody body) => | |
577 new FunctionExpression(null, parameters, body); | |
578 | |
579 static FunctionExpression functionExpression3( | |
580 TypeParameterList typeParameters, | |
581 FormalParameterList parameters, | |
582 FunctionBody body) => | |
583 new FunctionExpression(typeParameters, parameters, body); | |
584 | |
585 static FunctionExpressionInvocation functionExpressionInvocation( | |
586 Expression function, | |
587 [List<Expression> arguments]) => | |
588 functionExpressionInvocation2(function, null, arguments); | |
589 | |
590 static FunctionExpressionInvocation functionExpressionInvocation2( | |
591 Expression function, | |
592 [TypeArgumentList typeArguments, | |
593 List<Expression> arguments]) => | |
594 new FunctionExpressionInvocation( | |
595 function, typeArguments, argumentList(arguments)); | |
596 | |
597 static FunctionTypedFormalParameter functionTypedFormalParameter( | |
598 TypeName returnType, String identifier, | |
599 [List<FormalParameter> parameters]) => | |
600 new FunctionTypedFormalParameter(null, null, returnType, | |
601 identifier3(identifier), null, formalParameterList(parameters)); | |
602 | |
603 static HideCombinator hideCombinator(List<SimpleIdentifier> identifiers) => | |
604 new HideCombinator(TokenFactory.tokenFromString("hide"), identifiers); | |
605 | |
606 static HideCombinator hideCombinator2(List<String> identifiers) => | |
607 new HideCombinator( | |
608 TokenFactory.tokenFromString("hide"), identifierList(identifiers)); | |
609 | |
610 static PrefixedIdentifier identifier( | |
611 SimpleIdentifier prefix, SimpleIdentifier identifier) => | |
612 new PrefixedIdentifier( | |
613 prefix, TokenFactory.tokenFromType(TokenType.PERIOD), identifier); | |
614 | |
615 static SimpleIdentifier identifier3(String lexeme) => new SimpleIdentifier( | |
616 TokenFactory.tokenFromTypeAndString(TokenType.IDENTIFIER, lexeme)); | |
617 | |
618 static PrefixedIdentifier identifier4( | |
619 String prefix, SimpleIdentifier identifier) => | |
620 new PrefixedIdentifier(identifier3(prefix), | |
621 TokenFactory.tokenFromType(TokenType.PERIOD), identifier); | |
622 | |
623 static PrefixedIdentifier identifier5(String prefix, String identifier) => | |
624 new PrefixedIdentifier( | |
625 identifier3(prefix), | |
626 TokenFactory.tokenFromType(TokenType.PERIOD), | |
627 identifier3(identifier)); | |
628 | |
629 static List<SimpleIdentifier> identifierList(List<String> identifiers) { | |
630 if (identifiers == null) { | |
631 return null; | |
632 } | |
633 return identifiers | |
634 .map((String identifier) => identifier3(identifier)) | |
635 .toList(); | |
636 } | |
637 | |
638 static IfStatement ifStatement( | |
639 Expression condition, Statement thenStatement) => | |
640 ifStatement2(condition, thenStatement, null); | |
641 | |
642 static IfStatement ifStatement2(Expression condition, Statement thenStatement, | |
643 Statement elseStatement) => | |
644 new IfStatement( | |
645 TokenFactory.tokenFromKeyword(Keyword.IF), | |
646 TokenFactory.tokenFromType(TokenType.OPEN_PAREN), | |
647 condition, | |
648 TokenFactory.tokenFromType(TokenType.CLOSE_PAREN), | |
649 thenStatement, | |
650 elseStatement == null | |
651 ? null | |
652 : TokenFactory.tokenFromKeyword(Keyword.ELSE), | |
653 elseStatement); | |
654 | |
655 static ImplementsClause implementsClause(List<TypeName> types) => | |
656 new ImplementsClause( | |
657 TokenFactory.tokenFromKeyword(Keyword.IMPLEMENTS), types); | |
658 | |
659 static ImportDirective importDirective( | |
660 List<Annotation> metadata, String uri, bool isDeferred, String prefix, | |
661 [List<Combinator> combinators]) => | |
662 new ImportDirective( | |
663 null, | |
664 metadata, | |
665 TokenFactory.tokenFromKeyword(Keyword.IMPORT), | |
666 string2(uri), | |
667 null, | |
668 !isDeferred ? null : TokenFactory.tokenFromKeyword(Keyword.DEFERRED), | |
669 prefix == null ? null : TokenFactory.tokenFromKeyword(Keyword.AS), | |
670 prefix == null ? null : identifier3(prefix), | |
671 combinators, | |
672 TokenFactory.tokenFromType(TokenType.SEMICOLON)); | |
673 | |
674 static ImportDirective importDirective2( | |
675 String uri, bool isDeferred, String prefix, | |
676 [List<Combinator> combinators]) => | |
677 importDirective(null, uri, isDeferred, prefix, combinators); | |
678 | |
679 static ImportDirective importDirective3(String uri, String prefix, | |
680 [List<Combinator> combinators]) => | |
681 importDirective(null, uri, false, prefix, combinators); | |
682 | |
683 static IndexExpression indexExpression(Expression array, Expression index) => | |
684 new IndexExpression.forTarget( | |
685 array, | |
686 TokenFactory.tokenFromType(TokenType.OPEN_SQUARE_BRACKET), | |
687 index, | |
688 TokenFactory.tokenFromType(TokenType.CLOSE_SQUARE_BRACKET)); | |
689 | |
690 static InstanceCreationExpression instanceCreationExpression( | |
691 Keyword keyword, ConstructorName name, | |
692 [List<Expression> arguments]) => | |
693 new InstanceCreationExpression( | |
694 keyword == null ? null : TokenFactory.tokenFromKeyword(keyword), | |
695 name, | |
696 argumentList(arguments)); | |
697 | |
698 static InstanceCreationExpression instanceCreationExpression2( | |
699 Keyword keyword, TypeName type, | |
700 [List<Expression> arguments]) => | |
701 instanceCreationExpression3(keyword, type, null, arguments); | |
702 | |
703 static InstanceCreationExpression instanceCreationExpression3( | |
704 Keyword keyword, TypeName type, String identifier, | |
705 [List<Expression> arguments]) => | |
706 instanceCreationExpression( | |
707 keyword, | |
708 new ConstructorName( | |
709 type, | |
710 identifier == null | |
711 ? null | |
712 : TokenFactory.tokenFromType(TokenType.PERIOD), | |
713 identifier == null ? null : identifier3(identifier)), | |
714 arguments); | |
715 | |
716 static IntegerLiteral integer(int value) => new IntegerLiteral( | |
717 TokenFactory.tokenFromTypeAndString(TokenType.INT, value.toString()), | |
718 value); | |
719 | |
720 static InterpolationExpression interpolationExpression( | |
721 Expression expression) => | |
722 new InterpolationExpression( | |
723 TokenFactory.tokenFromType(TokenType.STRING_INTERPOLATION_EXPRESSION), | |
724 expression, | |
725 TokenFactory.tokenFromType(TokenType.CLOSE_CURLY_BRACKET)); | |
726 | |
727 static InterpolationExpression interpolationExpression2(String identifier) => | |
728 new InterpolationExpression( | |
729 TokenFactory.tokenFromType(TokenType.STRING_INTERPOLATION_IDENTIFIER), | |
730 identifier3(identifier), | |
731 null); | |
732 | |
733 static InterpolationString interpolationString( | |
734 String contents, String value) => | |
735 new InterpolationString(TokenFactory.tokenFromString(contents), value); | |
736 | |
737 static IsExpression isExpression( | |
738 Expression expression, bool negated, TypeName type) => | |
739 new IsExpression(expression, TokenFactory.tokenFromKeyword(Keyword.IS), | |
740 negated ? TokenFactory.tokenFromType(TokenType.BANG) : null, type); | |
741 | |
742 static Label label(SimpleIdentifier label) => | |
743 new Label(label, TokenFactory.tokenFromType(TokenType.COLON)); | |
744 | |
745 static Label label2(String label) => AstFactory.label(identifier3(label)); | |
746 | |
747 static LabeledStatement labeledStatement( | |
748 List<Label> labels, Statement statement) => | |
749 new LabeledStatement(labels, statement); | |
750 | |
751 static LibraryDirective libraryDirective( | |
752 List<Annotation> metadata, LibraryIdentifier libraryName) => | |
753 new LibraryDirective( | |
754 null, | |
755 metadata, | |
756 TokenFactory.tokenFromKeyword(Keyword.LIBRARY), | |
757 libraryName, | |
758 TokenFactory.tokenFromType(TokenType.SEMICOLON)); | |
759 | |
760 static LibraryDirective libraryDirective2(String libraryName) => | |
761 libraryDirective( | |
762 new List<Annotation>(), libraryIdentifier2([libraryName])); | |
763 | |
764 static LibraryIdentifier libraryIdentifier( | |
765 List<SimpleIdentifier> components) => | |
766 new LibraryIdentifier(components); | |
767 | |
768 static LibraryIdentifier libraryIdentifier2(List<String> components) { | |
769 return new LibraryIdentifier(identifierList(components)); | |
770 } | |
771 | |
772 static List list(List<Object> elements) { | |
773 return elements; | |
774 } | |
775 | |
776 static ListLiteral listLiteral([List<Expression> elements]) => | |
777 listLiteral2(null, null, elements); | |
778 | |
779 static ListLiteral listLiteral2( | |
780 Keyword keyword, TypeArgumentList typeArguments, | |
781 [List<Expression> elements]) => | |
782 new ListLiteral( | |
783 keyword == null ? null : TokenFactory.tokenFromKeyword(keyword), | |
784 typeArguments, | |
785 TokenFactory.tokenFromType(TokenType.OPEN_SQUARE_BRACKET), | |
786 elements, | |
787 TokenFactory.tokenFromType(TokenType.CLOSE_SQUARE_BRACKET)); | |
788 | |
789 static MapLiteral mapLiteral(Keyword keyword, TypeArgumentList typeArguments, | |
790 [List<MapLiteralEntry> entries]) => | |
791 new MapLiteral( | |
792 keyword == null ? null : TokenFactory.tokenFromKeyword(keyword), | |
793 typeArguments, | |
794 TokenFactory.tokenFromType(TokenType.OPEN_CURLY_BRACKET), | |
795 entries, | |
796 TokenFactory.tokenFromType(TokenType.CLOSE_CURLY_BRACKET)); | |
797 | |
798 static MapLiteral mapLiteral2([List<MapLiteralEntry> entries]) => | |
799 mapLiteral(null, null, entries); | |
800 | |
801 static MapLiteralEntry mapLiteralEntry(String key, Expression value) => | |
802 new MapLiteralEntry( | |
803 string2(key), TokenFactory.tokenFromType(TokenType.COLON), value); | |
804 | |
805 static MapLiteralEntry mapLiteralEntry2(Expression key, Expression value) => | |
806 new MapLiteralEntry( | |
807 key, TokenFactory.tokenFromType(TokenType.COLON), value); | |
808 | |
809 static MethodDeclaration methodDeclaration( | |
810 Keyword modifier, | |
811 TypeName returnType, | |
812 Keyword property, | |
813 Keyword operator, | |
814 SimpleIdentifier name, | |
815 FormalParameterList parameters) => | |
816 new MethodDeclaration( | |
817 null, | |
818 null, | |
819 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL), | |
820 modifier == null ? null : TokenFactory.tokenFromKeyword(modifier), | |
821 returnType, | |
822 property == null ? null : TokenFactory.tokenFromKeyword(property), | |
823 operator == null ? null : TokenFactory.tokenFromKeyword(operator), | |
824 name, | |
825 null, | |
826 parameters, | |
827 emptyFunctionBody()); | |
828 | |
829 static MethodDeclaration methodDeclaration2( | |
830 Keyword modifier, | |
831 TypeName returnType, | |
832 Keyword property, | |
833 Keyword operator, | |
834 SimpleIdentifier name, | |
835 FormalParameterList parameters, | |
836 FunctionBody body) => | |
837 new MethodDeclaration( | |
838 null, | |
839 null, | |
840 null, | |
841 modifier == null ? null : TokenFactory.tokenFromKeyword(modifier), | |
842 returnType, | |
843 property == null ? null : TokenFactory.tokenFromKeyword(property), | |
844 operator == null ? null : TokenFactory.tokenFromKeyword(operator), | |
845 name, | |
846 null, | |
847 parameters, | |
848 body); | |
849 | |
850 static MethodDeclaration methodDeclaration3( | |
851 Keyword modifier, | |
852 TypeName returnType, | |
853 Keyword property, | |
854 Keyword operator, | |
855 SimpleIdentifier name, | |
856 TypeParameterList typeParameters, | |
857 FormalParameterList parameters, | |
858 FunctionBody body) => | |
859 new MethodDeclaration( | |
860 null, | |
861 null, | |
862 null, | |
863 modifier == null ? null : TokenFactory.tokenFromKeyword(modifier), | |
864 returnType, | |
865 property == null ? null : TokenFactory.tokenFromKeyword(property), | |
866 operator == null ? null : TokenFactory.tokenFromKeyword(operator), | |
867 name, | |
868 typeParameters, | |
869 parameters, | |
870 body); | |
871 | |
872 static MethodDeclaration methodDeclaration4( | |
873 {bool external: false, | |
874 Keyword modifier, | |
875 TypeName returnType, | |
876 Keyword property, | |
877 bool operator: false, | |
878 String name, | |
879 FormalParameterList parameters, | |
880 FunctionBody body}) => | |
881 new MethodDeclaration( | |
882 null, | |
883 null, | |
884 external ? TokenFactory.tokenFromKeyword(Keyword.EXTERNAL) : null, | |
885 modifier == null ? null : TokenFactory.tokenFromKeyword(modifier), | |
886 returnType, | |
887 property == null ? null : TokenFactory.tokenFromKeyword(property), | |
888 operator ? TokenFactory.tokenFromKeyword(Keyword.OPERATOR) : null, | |
889 identifier3(name), | |
890 null, | |
891 parameters, | |
892 body); | |
893 | |
894 static MethodInvocation methodInvocation(Expression target, String methodName, | |
895 [List<Expression> arguments, | |
896 TokenType operator = TokenType.PERIOD]) => | |
897 new MethodInvocation( | |
898 target, | |
899 target == null ? null : TokenFactory.tokenFromType(operator), | |
900 identifier3(methodName), | |
901 null, | |
902 argumentList(arguments)); | |
903 | |
904 static MethodInvocation methodInvocation2(String methodName, | |
905 [List<Expression> arguments]) => | |
906 methodInvocation(null, methodName, arguments); | |
907 | |
908 static MethodInvocation methodInvocation3( | |
909 Expression target, String methodName, TypeArgumentList typeArguments, | |
910 [List<Expression> arguments, | |
911 TokenType operator = TokenType.PERIOD]) => | |
912 new MethodInvocation( | |
913 target, | |
914 target == null ? null : TokenFactory.tokenFromType(operator), | |
915 identifier3(methodName), | |
916 typeArguments, | |
917 argumentList(arguments)); | |
918 | |
919 static NamedExpression namedExpression(Label label, Expression expression) => | |
920 new NamedExpression(label, expression); | |
921 | |
922 static NamedExpression namedExpression2( | |
923 String label, Expression expression) => | |
924 namedExpression(label2(label), expression); | |
925 | |
926 static DefaultFormalParameter namedFormalParameter( | |
927 NormalFormalParameter parameter, Expression expression) => | |
928 new DefaultFormalParameter( | |
929 parameter, | |
930 ParameterKind.NAMED, | |
931 expression == null | |
932 ? null | |
933 : TokenFactory.tokenFromType(TokenType.COLON), | |
934 expression); | |
935 | |
936 static NativeClause nativeClause(String nativeCode) => new NativeClause( | |
937 TokenFactory.tokenFromString("native"), string2(nativeCode)); | |
938 | |
939 static NativeFunctionBody nativeFunctionBody(String nativeMethodName) => | |
940 new NativeFunctionBody( | |
941 TokenFactory.tokenFromString("native"), | |
942 string2(nativeMethodName), | |
943 TokenFactory.tokenFromType(TokenType.SEMICOLON)); | |
944 | |
945 static NullLiteral nullLiteral() => | |
946 new NullLiteral(TokenFactory.tokenFromKeyword(Keyword.NULL)); | |
947 | |
948 static ParenthesizedExpression parenthesizedExpression( | |
949 Expression expression) => | |
950 new ParenthesizedExpression( | |
951 TokenFactory.tokenFromType(TokenType.OPEN_PAREN), | |
952 expression, | |
953 TokenFactory.tokenFromType(TokenType.CLOSE_PAREN)); | |
954 | |
955 static PartDirective partDirective(List<Annotation> metadata, String url) => | |
956 new PartDirective( | |
957 null, | |
958 metadata, | |
959 TokenFactory.tokenFromKeyword(Keyword.PART), | |
960 string2(url), | |
961 TokenFactory.tokenFromType(TokenType.SEMICOLON)); | |
962 | |
963 static PartDirective partDirective2(String url) => | |
964 partDirective(new List<Annotation>(), url); | |
965 | |
966 static PartOfDirective partOfDirective(LibraryIdentifier libraryName) => | |
967 partOfDirective2(new List<Annotation>(), libraryName); | |
968 | |
969 static PartOfDirective partOfDirective2( | |
970 List<Annotation> metadata, LibraryIdentifier libraryName) => | |
971 new PartOfDirective( | |
972 null, | |
973 metadata, | |
974 TokenFactory.tokenFromKeyword(Keyword.PART), | |
975 TokenFactory.tokenFromString("of"), | |
976 libraryName, | |
977 TokenFactory.tokenFromType(TokenType.SEMICOLON)); | |
978 | |
979 static DefaultFormalParameter positionalFormalParameter( | |
980 NormalFormalParameter parameter, Expression expression) => | |
981 new DefaultFormalParameter( | |
982 parameter, | |
983 ParameterKind.POSITIONAL, | |
984 expression == null ? null : TokenFactory.tokenFromType(TokenType.EQ), | |
985 expression); | |
986 | |
987 static PostfixExpression postfixExpression( | |
988 Expression expression, TokenType operator) => | |
989 new PostfixExpression(expression, TokenFactory.tokenFromType(operator)); | |
990 | |
991 static PrefixExpression prefixExpression( | |
992 TokenType operator, Expression expression) => | |
993 new PrefixExpression(TokenFactory.tokenFromType(operator), expression); | |
994 | |
995 static PropertyAccess propertyAccess( | |
996 Expression target, SimpleIdentifier propertyName) => | |
997 new PropertyAccess( | |
998 target, TokenFactory.tokenFromType(TokenType.PERIOD), propertyName); | |
999 | |
1000 static PropertyAccess propertyAccess2(Expression target, String propertyName, | |
1001 [TokenType operator = TokenType.PERIOD]) => | |
1002 new PropertyAccess(target, TokenFactory.tokenFromType(operator), | |
1003 identifier3(propertyName)); | |
1004 | |
1005 static RedirectingConstructorInvocation redirectingConstructorInvocation( | |
1006 [List<Expression> arguments]) => | |
1007 redirectingConstructorInvocation2(null, arguments); | |
1008 | |
1009 static RedirectingConstructorInvocation redirectingConstructorInvocation2( | |
1010 String constructorName, | |
1011 [List<Expression> arguments]) => | |
1012 new RedirectingConstructorInvocation( | |
1013 TokenFactory.tokenFromKeyword(Keyword.THIS), | |
1014 constructorName == null | |
1015 ? null | |
1016 : TokenFactory.tokenFromType(TokenType.PERIOD), | |
1017 constructorName == null ? null : identifier3(constructorName), | |
1018 argumentList(arguments)); | |
1019 | |
1020 static RethrowExpression rethrowExpression() => | |
1021 new RethrowExpression(TokenFactory.tokenFromKeyword(Keyword.RETHROW)); | |
1022 | |
1023 static ReturnStatement returnStatement() => returnStatement2(null); | |
1024 | |
1025 static ReturnStatement returnStatement2(Expression expression) => | |
1026 new ReturnStatement(TokenFactory.tokenFromKeyword(Keyword.RETURN), | |
1027 expression, TokenFactory.tokenFromType(TokenType.SEMICOLON)); | |
1028 | |
1029 static ScriptTag scriptTag(String scriptTag) => | |
1030 new ScriptTag(TokenFactory.tokenFromString(scriptTag)); | |
1031 | |
1032 static ShowCombinator showCombinator(List<SimpleIdentifier> identifiers) => | |
1033 new ShowCombinator(TokenFactory.tokenFromString("show"), identifiers); | |
1034 | |
1035 static ShowCombinator showCombinator2(List<String> identifiers) => | |
1036 new ShowCombinator( | |
1037 TokenFactory.tokenFromString("show"), identifierList(identifiers)); | |
1038 | |
1039 static SimpleFormalParameter simpleFormalParameter( | |
1040 Keyword keyword, String parameterName) => | |
1041 simpleFormalParameter2(keyword, null, parameterName); | |
1042 | |
1043 static SimpleFormalParameter simpleFormalParameter2( | |
1044 Keyword keyword, TypeName type, String parameterName) => | |
1045 new SimpleFormalParameter( | |
1046 null, | |
1047 null, | |
1048 keyword == null ? null : TokenFactory.tokenFromKeyword(keyword), | |
1049 type, | |
1050 identifier3(parameterName)); | |
1051 | |
1052 static SimpleFormalParameter simpleFormalParameter3(String parameterName) => | |
1053 simpleFormalParameter2(null, null, parameterName); | |
1054 | |
1055 static SimpleFormalParameter simpleFormalParameter4( | |
1056 TypeName type, String parameterName) => | |
1057 simpleFormalParameter2(null, type, parameterName); | |
1058 | |
1059 static StringInterpolation string([List<InterpolationElement> elements]) => | |
1060 new StringInterpolation(elements); | |
1061 | |
1062 static SimpleStringLiteral string2(String content) => new SimpleStringLiteral( | |
1063 TokenFactory.tokenFromString("'$content'"), content); | |
1064 | |
1065 static SuperConstructorInvocation superConstructorInvocation( | |
1066 [List<Expression> arguments]) => | |
1067 superConstructorInvocation2(null, arguments); | |
1068 | |
1069 static SuperConstructorInvocation superConstructorInvocation2(String name, | |
1070 [List<Expression> arguments]) => | |
1071 new SuperConstructorInvocation( | |
1072 TokenFactory.tokenFromKeyword(Keyword.SUPER), | |
1073 name == null ? null : TokenFactory.tokenFromType(TokenType.PERIOD), | |
1074 name == null ? null : identifier3(name), | |
1075 argumentList(arguments)); | |
1076 | |
1077 static SuperExpression superExpression() => | |
1078 new SuperExpression(TokenFactory.tokenFromKeyword(Keyword.SUPER)); | |
1079 | |
1080 static SwitchCase switchCase( | |
1081 Expression expression, List<Statement> statements) => | |
1082 switchCase2(new List<Label>(), expression, statements); | |
1083 | |
1084 static SwitchCase switchCase2(List<Label> labels, Expression expression, | |
1085 List<Statement> statements) => | |
1086 new SwitchCase(labels, TokenFactory.tokenFromKeyword(Keyword.CASE), | |
1087 expression, TokenFactory.tokenFromType(TokenType.COLON), statements); | |
1088 | |
1089 static SwitchDefault switchDefault( | |
1090 List<Label> labels, List<Statement> statements) => | |
1091 new SwitchDefault(labels, TokenFactory.tokenFromKeyword(Keyword.DEFAULT), | |
1092 TokenFactory.tokenFromType(TokenType.COLON), statements); | |
1093 | |
1094 static SwitchDefault switchDefault2(List<Statement> statements) => | |
1095 switchDefault(new List<Label>(), statements); | |
1096 | |
1097 static SwitchStatement switchStatement( | |
1098 Expression expression, List<SwitchMember> members) => | |
1099 new SwitchStatement( | |
1100 TokenFactory.tokenFromKeyword(Keyword.SWITCH), | |
1101 TokenFactory.tokenFromType(TokenType.OPEN_PAREN), | |
1102 expression, | |
1103 TokenFactory.tokenFromType(TokenType.CLOSE_PAREN), | |
1104 TokenFactory.tokenFromType(TokenType.OPEN_CURLY_BRACKET), | |
1105 members, | |
1106 TokenFactory.tokenFromType(TokenType.CLOSE_CURLY_BRACKET)); | |
1107 | |
1108 static SymbolLiteral symbolLiteral(List<String> components) { | |
1109 List<Token> identifierList = new List<Token>(); | |
1110 for (String component in components) { | |
1111 identifierList.add( | |
1112 TokenFactory.tokenFromTypeAndString(TokenType.IDENTIFIER, component)); | |
1113 } | |
1114 return new SymbolLiteral( | |
1115 TokenFactory.tokenFromType(TokenType.HASH), identifierList); | |
1116 } | |
1117 | |
1118 static BlockFunctionBody syncBlockFunctionBody( | |
1119 [List<Statement> statements]) => | |
1120 new BlockFunctionBody( | |
1121 TokenFactory.tokenFromTypeAndString(TokenType.IDENTIFIER, "sync"), | |
1122 null, | |
1123 block(statements)); | |
1124 | |
1125 static BlockFunctionBody syncGeneratorBlockFunctionBody( | |
1126 [List<Statement> statements]) => | |
1127 new BlockFunctionBody( | |
1128 TokenFactory.tokenFromTypeAndString(TokenType.IDENTIFIER, "sync"), | |
1129 TokenFactory.tokenFromType(TokenType.STAR), | |
1130 block(statements)); | |
1131 | |
1132 static ThisExpression thisExpression() => | |
1133 new ThisExpression(TokenFactory.tokenFromKeyword(Keyword.THIS)); | |
1134 | |
1135 static ThrowExpression throwExpression() => throwExpression2(null); | |
1136 | |
1137 static ThrowExpression throwExpression2(Expression expression) => | |
1138 new ThrowExpression( | |
1139 TokenFactory.tokenFromKeyword(Keyword.THROW), expression); | |
1140 | |
1141 static TopLevelVariableDeclaration topLevelVariableDeclaration( | |
1142 Keyword keyword, | |
1143 TypeName type, | |
1144 List<VariableDeclaration> variables) => | |
1145 new TopLevelVariableDeclaration( | |
1146 null, | |
1147 null, | |
1148 variableDeclarationList(keyword, type, variables), | |
1149 TokenFactory.tokenFromType(TokenType.SEMICOLON)); | |
1150 | |
1151 static TopLevelVariableDeclaration topLevelVariableDeclaration2( | |
1152 Keyword keyword, List<VariableDeclaration> variables) => | |
1153 new TopLevelVariableDeclaration( | |
1154 null, | |
1155 null, | |
1156 variableDeclarationList(keyword, null, variables), | |
1157 TokenFactory.tokenFromType(TokenType.SEMICOLON)); | |
1158 | |
1159 static TryStatement tryStatement(Block body, Block finallyClause) => | |
1160 tryStatement3(body, new List<CatchClause>(), finallyClause); | |
1161 | |
1162 static TryStatement tryStatement2( | |
1163 Block body, List<CatchClause> catchClauses) => | |
1164 tryStatement3(body, catchClauses, null); | |
1165 | |
1166 static TryStatement tryStatement3( | |
1167 Block body, List<CatchClause> catchClauses, Block finallyClause) => | |
1168 new TryStatement( | |
1169 TokenFactory.tokenFromKeyword(Keyword.TRY), | |
1170 body, | |
1171 catchClauses, | |
1172 finallyClause == null | |
1173 ? null | |
1174 : TokenFactory.tokenFromKeyword(Keyword.FINALLY), | |
1175 finallyClause); | |
1176 | |
1177 static FunctionTypeAlias typeAlias(TypeName returnType, String name, | |
1178 TypeParameterList typeParameters, FormalParameterList parameters) => | |
1179 new FunctionTypeAlias( | |
1180 null, | |
1181 null, | |
1182 TokenFactory.tokenFromKeyword(Keyword.TYPEDEF), | |
1183 returnType, | |
1184 identifier3(name), | |
1185 typeParameters, | |
1186 parameters, | |
1187 TokenFactory.tokenFromType(TokenType.SEMICOLON)); | |
1188 | |
1189 static TypeArgumentList typeArgumentList(List<TypeName> typeNames) { | |
1190 if (typeNames == null || typeNames.length == 0) { | |
1191 return null; | |
1192 } | |
1193 return new TypeArgumentList(TokenFactory.tokenFromType(TokenType.LT), | |
1194 typeNames, TokenFactory.tokenFromType(TokenType.GT)); | |
1195 } | |
1196 | |
1197 /** | |
1198 * Create a type name whose name has been resolved to the given [element] and | |
1199 * whose type has been resolved to the type of the given element. | |
1200 * | |
1201 * <b>Note:</b> This method does not correctly handle class elements that have | |
1202 * type parameters. | |
1203 */ | |
1204 static TypeName typeName(ClassElement element, [List<TypeName> arguments]) { | |
1205 SimpleIdentifier name = identifier3(element.name); | |
1206 name.staticElement = element; | |
1207 TypeName typeName = typeName3(name, arguments); | |
1208 typeName.type = element.type; | |
1209 return typeName; | |
1210 } | |
1211 | |
1212 static TypeName typeName3(Identifier name, [List<TypeName> arguments]) => | |
1213 new TypeName(name, typeArgumentList(arguments)); | |
1214 | |
1215 static TypeName typeName4(String name, [List<TypeName> arguments]) => | |
1216 new TypeName(identifier3(name), typeArgumentList(arguments)); | |
1217 | |
1218 static TypeParameter typeParameter(String name) => | |
1219 new TypeParameter(null, null, identifier3(name), null, null); | |
1220 | |
1221 static TypeParameter typeParameter2(String name, TypeName bound) => | |
1222 new TypeParameter(null, null, identifier3(name), | |
1223 TokenFactory.tokenFromKeyword(Keyword.EXTENDS), bound); | |
1224 | |
1225 static TypeParameterList typeParameterList([List<String> typeNames]) { | |
1226 List<TypeParameter> typeParameters = null; | |
1227 if (typeNames != null && !typeNames.isEmpty) { | |
1228 typeParameters = new List<TypeParameter>(); | |
1229 for (String typeName in typeNames) { | |
1230 typeParameters.add(typeParameter(typeName)); | |
1231 } | |
1232 } | |
1233 return new TypeParameterList(TokenFactory.tokenFromType(TokenType.LT), | |
1234 typeParameters, TokenFactory.tokenFromType(TokenType.GT)); | |
1235 } | |
1236 | |
1237 static VariableDeclaration variableDeclaration(String name) => | |
1238 new VariableDeclaration(identifier3(name), null, null); | |
1239 | |
1240 static VariableDeclaration variableDeclaration2( | |
1241 String name, Expression initializer) => | |
1242 new VariableDeclaration(identifier3(name), | |
1243 TokenFactory.tokenFromType(TokenType.EQ), initializer); | |
1244 | |
1245 static VariableDeclarationList variableDeclarationList(Keyword keyword, | |
1246 TypeName type, List<VariableDeclaration> variables) => | |
1247 new VariableDeclarationList( | |
1248 null, | |
1249 null, | |
1250 keyword == null ? null : TokenFactory.tokenFromKeyword(keyword), | |
1251 type, | |
1252 variables); | |
1253 | |
1254 static VariableDeclarationList variableDeclarationList2( | |
1255 Keyword keyword, List<VariableDeclaration> variables) => | |
1256 variableDeclarationList(keyword, null, variables); | |
1257 | |
1258 static VariableDeclarationStatement variableDeclarationStatement( | |
1259 Keyword keyword, | |
1260 TypeName type, | |
1261 List<VariableDeclaration> variables) => | |
1262 new VariableDeclarationStatement( | |
1263 variableDeclarationList(keyword, type, variables), | |
1264 TokenFactory.tokenFromType(TokenType.SEMICOLON)); | |
1265 | |
1266 static VariableDeclarationStatement variableDeclarationStatement2( | |
1267 Keyword keyword, List<VariableDeclaration> variables) => | |
1268 variableDeclarationStatement(keyword, null, variables); | |
1269 | |
1270 static WhileStatement whileStatement(Expression condition, Statement body) => | |
1271 new WhileStatement( | |
1272 TokenFactory.tokenFromKeyword(Keyword.WHILE), | |
1273 TokenFactory.tokenFromType(TokenType.OPEN_PAREN), | |
1274 condition, | |
1275 TokenFactory.tokenFromType(TokenType.CLOSE_PAREN), | |
1276 body); | |
1277 | |
1278 static WithClause withClause(List<TypeName> types) => | |
1279 new WithClause(TokenFactory.tokenFromKeyword(Keyword.WITH), types); | |
1280 | |
1281 static YieldStatement yieldEachStatement(Expression expression) => | |
1282 new YieldStatement( | |
1283 TokenFactory.tokenFromTypeAndString(TokenType.IDENTIFIER, "yield"), | |
1284 TokenFactory.tokenFromType(TokenType.STAR), | |
1285 expression, | |
1286 TokenFactory.tokenFromType(TokenType.SEMICOLON)); | |
1287 | |
1288 static YieldStatement yieldStatement(Expression expression) => | |
1289 new YieldStatement( | |
1290 TokenFactory.tokenFromTypeAndString(TokenType.IDENTIFIER, "yield"), | |
1291 null, | |
1292 expression, | |
1293 TokenFactory.tokenFromType(TokenType.SEMICOLON)); | |
1294 } | |
OLD | NEW |