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