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

Side by Side Diff: packages/analyzer/lib/src/generated/testing/ast_test_factory.dart

Issue 2990843002: Removed fixed dependencies (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 engine.testing.ast_factory; 5 library analyzer.src.generated.testing.ast_test_factory;
6 6
7 import 'package:analyzer/src/generated/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/src/generated/element.dart'; 8 import 'package:analyzer/dart/ast/token.dart';
9 import 'package:analyzer/src/generated/scanner.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/src/dart/ast/ast.dart';
10 import 'package:analyzer/src/generated/testing/token_factory.dart'; 11 import 'package:analyzer/src/generated/testing/token_factory.dart';
11 import 'package:analyzer/src/generated/utilities_dart.dart'; 12 import 'package:analyzer/src/generated/utilities_dart.dart';
12 13
13 /** 14 /**
14 * 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
15 * 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
16 * 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.
17 * None of the nodes are resolved. 18 * None of the nodes are resolved.
18 * 19 *
19 * 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
20 * 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
21 * 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
22 * 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
23 * 'identifier' rather than 'prefixedIdentifier', or 'integer' rather than 'inte gerLiteral'. 24 * 'identifier' rather than 'prefixedIdentifier', or 'integer' rather than 'inte gerLiteral'.
24 */ 25 */
25 class AstFactory { 26 class AstTestFactory {
26 static AdjacentStrings adjacentStrings(List<StringLiteral> strings) => 27 static AdjacentStrings adjacentStrings(List<StringLiteral> strings) =>
27 new AdjacentStrings(strings); 28 new AdjacentStrings(strings);
28 29
29 static Annotation annotation(Identifier name) => new Annotation( 30 static Annotation annotation(Identifier name) => new Annotation(
30 TokenFactory.tokenFromType(TokenType.AT), name, null, null, null); 31 TokenFactory.tokenFromType(TokenType.AT), name, null, null, null);
31 32
32 static Annotation annotation2(Identifier name, 33 static Annotation annotation2(Identifier name,
33 SimpleIdentifier constructorName, ArgumentList arguments) => 34 SimpleIdentifier constructorName, ArgumentList arguments) =>
34 new Annotation( 35 new Annotation(
35 TokenFactory.tokenFromType(TokenType.AT), 36 TokenFactory.tokenFromType(TokenType.AT),
36 name, 37 name,
37 TokenFactory.tokenFromType(TokenType.PERIOD), 38 constructorName == null
39 ? null
40 : TokenFactory.tokenFromType(TokenType.PERIOD),
38 constructorName, 41 constructorName,
39 arguments); 42 arguments);
40 43
41 static ArgumentList argumentList([List<Expression> arguments]) => 44 static ArgumentList argumentList([List<Expression> arguments]) =>
42 new ArgumentList(TokenFactory.tokenFromType(TokenType.OPEN_PAREN), 45 new ArgumentList(TokenFactory.tokenFromType(TokenType.OPEN_PAREN),
43 arguments, TokenFactory.tokenFromType(TokenType.CLOSE_PAREN)); 46 arguments, TokenFactory.tokenFromType(TokenType.CLOSE_PAREN));
44 47
45 static AsExpression asExpression(Expression expression, TypeName type) => 48 static AsExpression asExpression(Expression expression, TypeName type) =>
46 new AsExpression( 49 new AsExpression(
47 expression, TokenFactory.tokenFromKeyword(Keyword.AS), type); 50 expression, TokenFactory.tokenFromKeyword(Keyword.AS), type);
48 51
49 static AssertStatement assertStatement(Expression condition) => 52 static AssertStatement assertStatement(Expression condition,
53 [Expression message]) =>
50 new AssertStatement( 54 new AssertStatement(
51 TokenFactory.tokenFromKeyword(Keyword.ASSERT), 55 TokenFactory.tokenFromKeyword(Keyword.ASSERT),
52 TokenFactory.tokenFromType(TokenType.OPEN_PAREN), 56 TokenFactory.tokenFromType(TokenType.OPEN_PAREN),
53 condition, 57 condition,
58 message == null ? null : TokenFactory.tokenFromType(TokenType.COMMA),
59 message,
54 TokenFactory.tokenFromType(TokenType.CLOSE_PAREN), 60 TokenFactory.tokenFromType(TokenType.CLOSE_PAREN),
55 TokenFactory.tokenFromType(TokenType.SEMICOLON)); 61 TokenFactory.tokenFromType(TokenType.SEMICOLON));
56 62
57 static AssignmentExpression assignmentExpression(Expression leftHandSide, 63 static AssignmentExpression assignmentExpression(Expression leftHandSide,
58 TokenType operator, Expression rightHandSide) => 64 TokenType operator, Expression rightHandSide) =>
59 new AssignmentExpression( 65 new AssignmentExpression(
60 leftHandSide, TokenFactory.tokenFromType(operator), rightHandSide); 66 leftHandSide, TokenFactory.tokenFromType(operator), rightHandSide);
61 67
62 static BlockFunctionBody asyncBlockFunctionBody( 68 static BlockFunctionBody asyncBlockFunctionBody(
63 [List<Statement> statements]) => 69 [List<Statement> statements]) =>
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 static CompilationUnit compilationUnit7( 262 static CompilationUnit compilationUnit7(
257 String scriptTag, List<Directive> directives) => 263 String scriptTag, List<Directive> directives) =>
258 compilationUnit8(scriptTag, directives, null); 264 compilationUnit8(scriptTag, directives, null);
259 265
260 static CompilationUnit compilationUnit8( 266 static CompilationUnit compilationUnit8(
261 String scriptTag, 267 String scriptTag,
262 List<Directive> directives, 268 List<Directive> directives,
263 List<CompilationUnitMember> declarations) => 269 List<CompilationUnitMember> declarations) =>
264 new CompilationUnit( 270 new CompilationUnit(
265 TokenFactory.tokenFromType(TokenType.EOF), 271 TokenFactory.tokenFromType(TokenType.EOF),
266 scriptTag == null ? null : AstFactory.scriptTag(scriptTag), 272 scriptTag == null ? null : AstTestFactory.scriptTag(scriptTag),
267 directives == null ? new List<Directive>() : directives, 273 directives == null ? new List<Directive>() : directives,
268 declarations == null 274 declarations == null
269 ? new List<CompilationUnitMember>() 275 ? new List<CompilationUnitMember>()
270 : declarations, 276 : declarations,
271 TokenFactory.tokenFromType(TokenType.EOF)); 277 TokenFactory.tokenFromType(TokenType.EOF));
272 278
273 static ConditionalExpression conditionalExpression(Expression condition, 279 static ConditionalExpression conditionalExpression(Expression condition,
274 Expression thenExpression, Expression elseExpression) => 280 Expression thenExpression, Expression elseExpression) =>
275 new ConditionalExpression( 281 new ConditionalExpression(
276 condition, 282 condition,
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 return enumDeclaration(identifier3(name), constants); 430 return enumDeclaration(identifier3(name), constants);
425 } 431 }
426 432
427 static ExportDirective exportDirective(List<Annotation> metadata, String uri, 433 static ExportDirective exportDirective(List<Annotation> metadata, String uri,
428 [List<Combinator> combinators]) => 434 [List<Combinator> combinators]) =>
429 new ExportDirective( 435 new ExportDirective(
430 null, 436 null,
431 metadata, 437 metadata,
432 TokenFactory.tokenFromKeyword(Keyword.EXPORT), 438 TokenFactory.tokenFromKeyword(Keyword.EXPORT),
433 string2(uri), 439 string2(uri),
440 null,
434 combinators, 441 combinators,
435 TokenFactory.tokenFromType(TokenType.SEMICOLON)); 442 TokenFactory.tokenFromType(TokenType.SEMICOLON));
436 443
437 static ExportDirective exportDirective2(String uri, 444 static ExportDirective exportDirective2(String uri,
438 [List<Combinator> combinators]) => 445 [List<Combinator> combinators]) =>
439 exportDirective(null, uri, combinators); 446 exportDirective(null, uri, combinators);
440 447
441 static ExpressionFunctionBody expressionFunctionBody(Expression expression) => 448 static ExpressionFunctionBody expressionFunctionBody(Expression expression) =>
442 new ExpressionFunctionBody( 449 new ExpressionFunctionBody(
443 null, 450 null,
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 TokenFactory.tokenFromKeyword(Keyword.IMPLEMENTS), types); 657 TokenFactory.tokenFromKeyword(Keyword.IMPLEMENTS), types);
651 658
652 static ImportDirective importDirective( 659 static ImportDirective importDirective(
653 List<Annotation> metadata, String uri, bool isDeferred, String prefix, 660 List<Annotation> metadata, String uri, bool isDeferred, String prefix,
654 [List<Combinator> combinators]) => 661 [List<Combinator> combinators]) =>
655 new ImportDirective( 662 new ImportDirective(
656 null, 663 null,
657 metadata, 664 metadata,
658 TokenFactory.tokenFromKeyword(Keyword.IMPORT), 665 TokenFactory.tokenFromKeyword(Keyword.IMPORT),
659 string2(uri), 666 string2(uri),
667 null,
660 !isDeferred ? null : TokenFactory.tokenFromKeyword(Keyword.DEFERRED), 668 !isDeferred ? null : TokenFactory.tokenFromKeyword(Keyword.DEFERRED),
661 prefix == null ? null : TokenFactory.tokenFromKeyword(Keyword.AS), 669 prefix == null ? null : TokenFactory.tokenFromKeyword(Keyword.AS),
662 prefix == null ? null : identifier3(prefix), 670 prefix == null ? null : identifier3(prefix),
663 combinators, 671 combinators,
664 TokenFactory.tokenFromType(TokenType.SEMICOLON)); 672 TokenFactory.tokenFromType(TokenType.SEMICOLON));
665 673
666 static ImportDirective importDirective2( 674 static ImportDirective importDirective2(
667 String uri, bool isDeferred, String prefix, 675 String uri, bool isDeferred, String prefix,
668 [List<Combinator> combinators]) => 676 [List<Combinator> combinators]) =>
669 importDirective(null, uri, isDeferred, prefix, combinators); 677 importDirective(null, uri, isDeferred, prefix, combinators);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 new InterpolationString(TokenFactory.tokenFromString(contents), value); 735 new InterpolationString(TokenFactory.tokenFromString(contents), value);
728 736
729 static IsExpression isExpression( 737 static IsExpression isExpression(
730 Expression expression, bool negated, TypeName type) => 738 Expression expression, bool negated, TypeName type) =>
731 new IsExpression(expression, TokenFactory.tokenFromKeyword(Keyword.IS), 739 new IsExpression(expression, TokenFactory.tokenFromKeyword(Keyword.IS),
732 negated ? TokenFactory.tokenFromType(TokenType.BANG) : null, type); 740 negated ? TokenFactory.tokenFromType(TokenType.BANG) : null, type);
733 741
734 static Label label(SimpleIdentifier label) => 742 static Label label(SimpleIdentifier label) =>
735 new Label(label, TokenFactory.tokenFromType(TokenType.COLON)); 743 new Label(label, TokenFactory.tokenFromType(TokenType.COLON));
736 744
737 static Label label2(String label) => AstFactory.label(identifier3(label)); 745 static Label label2(String label) => AstTestFactory.label(identifier3(label));
738 746
739 static LabeledStatement labeledStatement( 747 static LabeledStatement labeledStatement(
740 List<Label> labels, Statement statement) => 748 List<Label> labels, Statement statement) =>
741 new LabeledStatement(labels, statement); 749 new LabeledStatement(labels, statement);
742 750
743 static LibraryDirective libraryDirective( 751 static LibraryDirective libraryDirective(
744 List<Annotation> metadata, LibraryIdentifier libraryName) => 752 List<Annotation> metadata, LibraryIdentifier libraryName) =>
745 new LibraryDirective( 753 new LibraryDirective(
746 null, 754 null,
747 metadata, 755 metadata,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 entries, 795 entries,
788 TokenFactory.tokenFromType(TokenType.CLOSE_CURLY_BRACKET)); 796 TokenFactory.tokenFromType(TokenType.CLOSE_CURLY_BRACKET));
789 797
790 static MapLiteral mapLiteral2([List<MapLiteralEntry> entries]) => 798 static MapLiteral mapLiteral2([List<MapLiteralEntry> entries]) =>
791 mapLiteral(null, null, entries); 799 mapLiteral(null, null, entries);
792 800
793 static MapLiteralEntry mapLiteralEntry(String key, Expression value) => 801 static MapLiteralEntry mapLiteralEntry(String key, Expression value) =>
794 new MapLiteralEntry( 802 new MapLiteralEntry(
795 string2(key), TokenFactory.tokenFromType(TokenType.COLON), value); 803 string2(key), TokenFactory.tokenFromType(TokenType.COLON), value);
796 804
805 static MapLiteralEntry mapLiteralEntry2(Expression key, Expression value) =>
806 new MapLiteralEntry(
807 key, TokenFactory.tokenFromType(TokenType.COLON), value);
808
797 static MethodDeclaration methodDeclaration( 809 static MethodDeclaration methodDeclaration(
798 Keyword modifier, 810 Keyword modifier,
799 TypeName returnType, 811 TypeName returnType,
800 Keyword property, 812 Keyword property,
801 Keyword operator, 813 Keyword operator,
802 SimpleIdentifier name, 814 SimpleIdentifier name,
803 FormalParameterList parameters) => 815 FormalParameterList parameters) =>
804 new MethodDeclaration( 816 new MethodDeclaration(
805 null, 817 null,
806 null, 818 null,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 null, 862 null,
851 modifier == null ? null : TokenFactory.tokenFromKeyword(modifier), 863 modifier == null ? null : TokenFactory.tokenFromKeyword(modifier),
852 returnType, 864 returnType,
853 property == null ? null : TokenFactory.tokenFromKeyword(property), 865 property == null ? null : TokenFactory.tokenFromKeyword(property),
854 operator == null ? null : TokenFactory.tokenFromKeyword(operator), 866 operator == null ? null : TokenFactory.tokenFromKeyword(operator),
855 name, 867 name,
856 typeParameters, 868 typeParameters,
857 parameters, 869 parameters,
858 body); 870 body);
859 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
860 static MethodInvocation methodInvocation(Expression target, String methodName, 894 static MethodInvocation methodInvocation(Expression target, String methodName,
861 [List<Expression> arguments, 895 [List<Expression> arguments,
862 TokenType operator = TokenType.PERIOD]) => 896 TokenType operator = TokenType.PERIOD]) =>
863 new MethodInvocation( 897 new MethodInvocation(
864 target, 898 target,
865 target == null ? null : TokenFactory.tokenFromType(operator), 899 target == null ? null : TokenFactory.tokenFromType(operator),
866 identifier3(methodName), 900 identifier3(methodName),
867 null, 901 null,
868 argumentList(arguments)); 902 argumentList(arguments));
869 903
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
1251 expression, 1285 expression,
1252 TokenFactory.tokenFromType(TokenType.SEMICOLON)); 1286 TokenFactory.tokenFromType(TokenType.SEMICOLON));
1253 1287
1254 static YieldStatement yieldStatement(Expression expression) => 1288 static YieldStatement yieldStatement(Expression expression) =>
1255 new YieldStatement( 1289 new YieldStatement(
1256 TokenFactory.tokenFromTypeAndString(TokenType.IDENTIFIER, "yield"), 1290 TokenFactory.tokenFromTypeAndString(TokenType.IDENTIFIER, "yield"),
1257 null, 1291 null,
1258 expression, 1292 expression,
1259 TokenFactory.tokenFromType(TokenType.SEMICOLON)); 1293 TokenFactory.tokenFromType(TokenType.SEMICOLON));
1260 } 1294 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698