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

Side by Side Diff: packages/analyzer/lib/src/generated/testing/ast_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_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 `AstFactory` 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'.
25 *
26 * Deprecated. Please use [AstTestFactory] instead.
24 */ 27 */
28 @deprecated
25 class AstFactory { 29 class AstFactory {
26 static AdjacentStrings adjacentStrings(List<StringLiteral> strings) => 30 static AdjacentStrings adjacentStrings(List<StringLiteral> strings) =>
27 new AdjacentStrings(strings); 31 new AdjacentStrings(strings);
28 32
29 static Annotation annotation(Identifier name) => new Annotation( 33 static Annotation annotation(Identifier name) => new Annotation(
30 TokenFactory.tokenFromType(TokenType.AT), name, null, null, null); 34 TokenFactory.tokenFromType(TokenType.AT), name, null, null, null);
31 35
32 static Annotation annotation2(Identifier name, 36 static Annotation annotation2(Identifier name,
33 SimpleIdentifier constructorName, ArgumentList arguments) => 37 SimpleIdentifier constructorName, ArgumentList arguments) =>
34 new Annotation( 38 new Annotation(
35 TokenFactory.tokenFromType(TokenType.AT), 39 TokenFactory.tokenFromType(TokenType.AT),
36 name, 40 name,
37 TokenFactory.tokenFromType(TokenType.PERIOD), 41 constructorName == null
42 ? null
43 : TokenFactory.tokenFromType(TokenType.PERIOD),
38 constructorName, 44 constructorName,
39 arguments); 45 arguments);
40 46
41 static ArgumentList argumentList([List<Expression> arguments]) => 47 static ArgumentList argumentList([List<Expression> arguments]) =>
42 new ArgumentList(TokenFactory.tokenFromType(TokenType.OPEN_PAREN), 48 new ArgumentList(TokenFactory.tokenFromType(TokenType.OPEN_PAREN),
43 arguments, TokenFactory.tokenFromType(TokenType.CLOSE_PAREN)); 49 arguments, TokenFactory.tokenFromType(TokenType.CLOSE_PAREN));
44 50
45 static AsExpression asExpression(Expression expression, TypeName type) => 51 static AsExpression asExpression(Expression expression, TypeName type) =>
46 new AsExpression( 52 new AsExpression(
47 expression, TokenFactory.tokenFromKeyword(Keyword.AS), type); 53 expression, TokenFactory.tokenFromKeyword(Keyword.AS), type);
48 54
49 static AssertStatement assertStatement(Expression condition) => 55 static AssertStatement assertStatement(Expression condition,
56 [Expression message]) =>
50 new AssertStatement( 57 new AssertStatement(
51 TokenFactory.tokenFromKeyword(Keyword.ASSERT), 58 TokenFactory.tokenFromKeyword(Keyword.ASSERT),
52 TokenFactory.tokenFromType(TokenType.OPEN_PAREN), 59 TokenFactory.tokenFromType(TokenType.OPEN_PAREN),
53 condition, 60 condition,
61 message == null ? null : TokenFactory.tokenFromType(TokenType.COMMA),
62 message,
54 TokenFactory.tokenFromType(TokenType.CLOSE_PAREN), 63 TokenFactory.tokenFromType(TokenType.CLOSE_PAREN),
55 TokenFactory.tokenFromType(TokenType.SEMICOLON)); 64 TokenFactory.tokenFromType(TokenType.SEMICOLON));
56 65
57 static AssignmentExpression assignmentExpression(Expression leftHandSide, 66 static AssignmentExpression assignmentExpression(Expression leftHandSide,
58 TokenType operator, Expression rightHandSide) => 67 TokenType operator, Expression rightHandSide) =>
59 new AssignmentExpression( 68 new AssignmentExpression(
60 leftHandSide, TokenFactory.tokenFromType(operator), rightHandSide); 69 leftHandSide, TokenFactory.tokenFromType(operator), rightHandSide);
61 70
62 static BlockFunctionBody asyncBlockFunctionBody( 71 static BlockFunctionBody asyncBlockFunctionBody(
63 [List<Statement> statements]) => 72 [List<Statement> statements]) =>
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 return enumDeclaration(identifier3(name), constants); 433 return enumDeclaration(identifier3(name), constants);
425 } 434 }
426 435
427 static ExportDirective exportDirective(List<Annotation> metadata, String uri, 436 static ExportDirective exportDirective(List<Annotation> metadata, String uri,
428 [List<Combinator> combinators]) => 437 [List<Combinator> combinators]) =>
429 new ExportDirective( 438 new ExportDirective(
430 null, 439 null,
431 metadata, 440 metadata,
432 TokenFactory.tokenFromKeyword(Keyword.EXPORT), 441 TokenFactory.tokenFromKeyword(Keyword.EXPORT),
433 string2(uri), 442 string2(uri),
443 null,
434 combinators, 444 combinators,
435 TokenFactory.tokenFromType(TokenType.SEMICOLON)); 445 TokenFactory.tokenFromType(TokenType.SEMICOLON));
436 446
437 static ExportDirective exportDirective2(String uri, 447 static ExportDirective exportDirective2(String uri,
438 [List<Combinator> combinators]) => 448 [List<Combinator> combinators]) =>
439 exportDirective(null, uri, combinators); 449 exportDirective(null, uri, combinators);
440 450
441 static ExpressionFunctionBody expressionFunctionBody(Expression expression) => 451 static ExpressionFunctionBody expressionFunctionBody(Expression expression) =>
442 new ExpressionFunctionBody( 452 new ExpressionFunctionBody(
443 null, 453 null,
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 TokenFactory.tokenFromKeyword(Keyword.IMPLEMENTS), types); 660 TokenFactory.tokenFromKeyword(Keyword.IMPLEMENTS), types);
651 661
652 static ImportDirective importDirective( 662 static ImportDirective importDirective(
653 List<Annotation> metadata, String uri, bool isDeferred, String prefix, 663 List<Annotation> metadata, String uri, bool isDeferred, String prefix,
654 [List<Combinator> combinators]) => 664 [List<Combinator> combinators]) =>
655 new ImportDirective( 665 new ImportDirective(
656 null, 666 null,
657 metadata, 667 metadata,
658 TokenFactory.tokenFromKeyword(Keyword.IMPORT), 668 TokenFactory.tokenFromKeyword(Keyword.IMPORT),
659 string2(uri), 669 string2(uri),
670 null,
660 !isDeferred ? null : TokenFactory.tokenFromKeyword(Keyword.DEFERRED), 671 !isDeferred ? null : TokenFactory.tokenFromKeyword(Keyword.DEFERRED),
661 prefix == null ? null : TokenFactory.tokenFromKeyword(Keyword.AS), 672 prefix == null ? null : TokenFactory.tokenFromKeyword(Keyword.AS),
662 prefix == null ? null : identifier3(prefix), 673 prefix == null ? null : identifier3(prefix),
663 combinators, 674 combinators,
664 TokenFactory.tokenFromType(TokenType.SEMICOLON)); 675 TokenFactory.tokenFromType(TokenType.SEMICOLON));
665 676
666 static ImportDirective importDirective2( 677 static ImportDirective importDirective2(
667 String uri, bool isDeferred, String prefix, 678 String uri, bool isDeferred, String prefix,
668 [List<Combinator> combinators]) => 679 [List<Combinator> combinators]) =>
669 importDirective(null, uri, isDeferred, prefix, combinators); 680 importDirective(null, uri, isDeferred, prefix, combinators);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 entries, 798 entries,
788 TokenFactory.tokenFromType(TokenType.CLOSE_CURLY_BRACKET)); 799 TokenFactory.tokenFromType(TokenType.CLOSE_CURLY_BRACKET));
789 800
790 static MapLiteral mapLiteral2([List<MapLiteralEntry> entries]) => 801 static MapLiteral mapLiteral2([List<MapLiteralEntry> entries]) =>
791 mapLiteral(null, null, entries); 802 mapLiteral(null, null, entries);
792 803
793 static MapLiteralEntry mapLiteralEntry(String key, Expression value) => 804 static MapLiteralEntry mapLiteralEntry(String key, Expression value) =>
794 new MapLiteralEntry( 805 new MapLiteralEntry(
795 string2(key), TokenFactory.tokenFromType(TokenType.COLON), value); 806 string2(key), TokenFactory.tokenFromType(TokenType.COLON), value);
796 807
808 static MapLiteralEntry mapLiteralEntry2(Expression key, Expression value) =>
809 new MapLiteralEntry(
810 key, TokenFactory.tokenFromType(TokenType.COLON), value);
811
797 static MethodDeclaration methodDeclaration( 812 static MethodDeclaration methodDeclaration(
798 Keyword modifier, 813 Keyword modifier,
799 TypeName returnType, 814 TypeName returnType,
800 Keyword property, 815 Keyword property,
801 Keyword operator, 816 Keyword operator,
802 SimpleIdentifier name, 817 SimpleIdentifier name,
803 FormalParameterList parameters) => 818 FormalParameterList parameters) =>
804 new MethodDeclaration( 819 new MethodDeclaration(
805 null, 820 null,
806 null, 821 null,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 null, 865 null,
851 modifier == null ? null : TokenFactory.tokenFromKeyword(modifier), 866 modifier == null ? null : TokenFactory.tokenFromKeyword(modifier),
852 returnType, 867 returnType,
853 property == null ? null : TokenFactory.tokenFromKeyword(property), 868 property == null ? null : TokenFactory.tokenFromKeyword(property),
854 operator == null ? null : TokenFactory.tokenFromKeyword(operator), 869 operator == null ? null : TokenFactory.tokenFromKeyword(operator),
855 name, 870 name,
856 typeParameters, 871 typeParameters,
857 parameters, 872 parameters,
858 body); 873 body);
859 874
875 static MethodDeclaration methodDeclaration4(
876 {bool external: false,
877 Keyword modifier,
878 TypeName returnType,
879 Keyword property,
880 bool operator: false,
881 String name,
882 FormalParameterList parameters,
883 FunctionBody body}) =>
884 new MethodDeclaration(
885 null,
886 null,
887 external ? TokenFactory.tokenFromKeyword(Keyword.EXTERNAL) : null,
888 modifier == null ? null : TokenFactory.tokenFromKeyword(modifier),
889 returnType,
890 property == null ? null : TokenFactory.tokenFromKeyword(property),
891 operator ? TokenFactory.tokenFromKeyword(Keyword.OPERATOR) : null,
892 identifier3(name),
893 null,
894 parameters,
895 body);
896
860 static MethodInvocation methodInvocation(Expression target, String methodName, 897 static MethodInvocation methodInvocation(Expression target, String methodName,
861 [List<Expression> arguments, 898 [List<Expression> arguments,
862 TokenType operator = TokenType.PERIOD]) => 899 TokenType operator = TokenType.PERIOD]) =>
863 new MethodInvocation( 900 new MethodInvocation(
864 target, 901 target,
865 target == null ? null : TokenFactory.tokenFromType(operator), 902 target == null ? null : TokenFactory.tokenFromType(operator),
866 identifier3(methodName), 903 identifier3(methodName),
867 null, 904 null,
868 argumentList(arguments)); 905 argumentList(arguments));
869 906
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
1251 expression, 1288 expression,
1252 TokenFactory.tokenFromType(TokenType.SEMICOLON)); 1289 TokenFactory.tokenFromType(TokenType.SEMICOLON));
1253 1290
1254 static YieldStatement yieldStatement(Expression expression) => 1291 static YieldStatement yieldStatement(Expression expression) =>
1255 new YieldStatement( 1292 new YieldStatement(
1256 TokenFactory.tokenFromTypeAndString(TokenType.IDENTIFIER, "yield"), 1293 TokenFactory.tokenFromTypeAndString(TokenType.IDENTIFIER, "yield"),
1257 null, 1294 null,
1258 expression, 1295 expression,
1259 TokenFactory.tokenFromType(TokenType.SEMICOLON)); 1296 TokenFactory.tokenFromType(TokenType.SEMICOLON));
1260 } 1297 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698