OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library analyzer.src.generated.testing.ast_factory; | 5 library analyzer.src.generated.testing.ast_test_factory; |
6 | 6 |
7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
8 import 'package:analyzer/dart/ast/token.dart'; | 8 import 'package:analyzer/dart/ast/token.dart'; |
9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
10 import 'package:analyzer/src/dart/ast/ast.dart'; | 10 import 'package:analyzer/src/dart/ast/ast.dart'; |
11 import 'package:analyzer/src/generated/testing/token_factory.dart'; | 11 import 'package:analyzer/src/generated/testing/token_factory.dart'; |
12 import 'package:analyzer/src/generated/utilities_dart.dart'; | 12 import 'package:analyzer/src/generated/utilities_dart.dart'; |
13 | 13 |
14 /** | 14 /** |
15 * The class `AstFactory` defines utility methods that can be used to create AST
nodes. The | 15 * The class `AstTestFactory` 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 | 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. | 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. | 18 * None of the nodes are resolved. |
19 * | 19 * |
20 * The general pattern is for the name of the factory method to be the same as t
he name of the class | 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 | 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 | 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 | 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'. | 24 * 'identifier' rather than 'prefixedIdentifier', or 'integer' rather than 'inte
gerLiteral'. |
25 */ | 25 */ |
26 class AstFactory { | 26 class AstTestFactory { |
27 static AdjacentStrings adjacentStrings(List<StringLiteral> strings) => | 27 static AdjacentStrings adjacentStrings(List<StringLiteral> strings) => |
28 new AdjacentStrings(strings); | 28 new AdjacentStrings(strings); |
29 | 29 |
30 static Annotation annotation(Identifier name) => new Annotation( | 30 static Annotation annotation(Identifier name) => new Annotation( |
31 TokenFactory.tokenFromType(TokenType.AT), name, null, null, null); | 31 TokenFactory.tokenFromType(TokenType.AT), name, null, null, null); |
32 | 32 |
33 static Annotation annotation2(Identifier name, | 33 static Annotation annotation2(Identifier name, |
34 SimpleIdentifier constructorName, ArgumentList arguments) => | 34 SimpleIdentifier constructorName, ArgumentList arguments) => |
35 new Annotation( | 35 new Annotation( |
36 TokenFactory.tokenFromType(TokenType.AT), | 36 TokenFactory.tokenFromType(TokenType.AT), |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 static CompilationUnit compilationUnit7( | 262 static CompilationUnit compilationUnit7( |
263 String scriptTag, List<Directive> directives) => | 263 String scriptTag, List<Directive> directives) => |
264 compilationUnit8(scriptTag, directives, null); | 264 compilationUnit8(scriptTag, directives, null); |
265 | 265 |
266 static CompilationUnit compilationUnit8( | 266 static CompilationUnit compilationUnit8( |
267 String scriptTag, | 267 String scriptTag, |
268 List<Directive> directives, | 268 List<Directive> directives, |
269 List<CompilationUnitMember> declarations) => | 269 List<CompilationUnitMember> declarations) => |
270 new CompilationUnit( | 270 new CompilationUnit( |
271 TokenFactory.tokenFromType(TokenType.EOF), | 271 TokenFactory.tokenFromType(TokenType.EOF), |
272 scriptTag == null ? null : AstFactory.scriptTag(scriptTag), | 272 scriptTag == null ? null : AstTestFactory.scriptTag(scriptTag), |
273 directives == null ? new List<Directive>() : directives, | 273 directives == null ? new List<Directive>() : directives, |
274 declarations == null | 274 declarations == null |
275 ? new List<CompilationUnitMember>() | 275 ? new List<CompilationUnitMember>() |
276 : declarations, | 276 : declarations, |
277 TokenFactory.tokenFromType(TokenType.EOF)); | 277 TokenFactory.tokenFromType(TokenType.EOF)); |
278 | 278 |
279 static ConditionalExpression conditionalExpression(Expression condition, | 279 static ConditionalExpression conditionalExpression(Expression condition, |
280 Expression thenExpression, Expression elseExpression) => | 280 Expression thenExpression, Expression elseExpression) => |
281 new ConditionalExpression( | 281 new ConditionalExpression( |
282 condition, | 282 condition, |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 new InterpolationString(TokenFactory.tokenFromString(contents), value); | 735 new InterpolationString(TokenFactory.tokenFromString(contents), value); |
736 | 736 |
737 static IsExpression isExpression( | 737 static IsExpression isExpression( |
738 Expression expression, bool negated, TypeName type) => | 738 Expression expression, bool negated, TypeName type) => |
739 new IsExpression(expression, TokenFactory.tokenFromKeyword(Keyword.IS), | 739 new IsExpression(expression, TokenFactory.tokenFromKeyword(Keyword.IS), |
740 negated ? TokenFactory.tokenFromType(TokenType.BANG) : null, type); | 740 negated ? TokenFactory.tokenFromType(TokenType.BANG) : null, type); |
741 | 741 |
742 static Label label(SimpleIdentifier label) => | 742 static Label label(SimpleIdentifier label) => |
743 new Label(label, TokenFactory.tokenFromType(TokenType.COLON)); | 743 new Label(label, TokenFactory.tokenFromType(TokenType.COLON)); |
744 | 744 |
745 static Label label2(String label) => AstFactory.label(identifier3(label)); | 745 static Label label2(String label) => AstTestFactory.label(identifier3(label)); |
746 | 746 |
747 static LabeledStatement labeledStatement( | 747 static LabeledStatement labeledStatement( |
748 List<Label> labels, Statement statement) => | 748 List<Label> labels, Statement statement) => |
749 new LabeledStatement(labels, statement); | 749 new LabeledStatement(labels, statement); |
750 | 750 |
751 static LibraryDirective libraryDirective( | 751 static LibraryDirective libraryDirective( |
752 List<Annotation> metadata, LibraryIdentifier libraryName) => | 752 List<Annotation> metadata, LibraryIdentifier libraryName) => |
753 new LibraryDirective( | 753 new LibraryDirective( |
754 null, | 754 null, |
755 metadata, | 755 metadata, |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1285 expression, | 1285 expression, |
1286 TokenFactory.tokenFromType(TokenType.SEMICOLON)); | 1286 TokenFactory.tokenFromType(TokenType.SEMICOLON)); |
1287 | 1287 |
1288 static YieldStatement yieldStatement(Expression expression) => | 1288 static YieldStatement yieldStatement(Expression expression) => |
1289 new YieldStatement( | 1289 new YieldStatement( |
1290 TokenFactory.tokenFromTypeAndString(TokenType.IDENTIFIER, "yield"), | 1290 TokenFactory.tokenFromTypeAndString(TokenType.IDENTIFIER, "yield"), |
1291 null, | 1291 null, |
1292 expression, | 1292 expression, |
1293 TokenFactory.tokenFromType(TokenType.SEMICOLON)); | 1293 TokenFactory.tokenFromType(TokenType.SEMICOLON)); |
1294 } | 1294 } |
OLD | NEW |