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

Side by Side Diff: pkg/analyzer/test/generated/ast_test.dart

Issue 351283003: Move Tokenfactory, AstFactory and ElementFactory from tests to the testing/ Folder. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer/pubspec.yaml ('k') | pkg/analyzer/test/generated/element_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // This code was auto-generated, is not intended to be edited, and is subject to 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. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.ast_test; 8 library engine.ast_test;
9 9
10 import 'package:analyzer/src/generated/java_core.dart'; 10 import 'package:analyzer/src/generated/java_core.dart';
11 import 'package:analyzer/src/generated/java_engine.dart'; 11 import 'package:analyzer/src/generated/java_engine.dart';
12 import 'package:analyzer/src/generated/java_junit.dart'; 12 import 'package:analyzer/src/generated/java_junit.dart';
13 import 'package:analyzer/src/generated/java_engine.dart' show Predicate; 13 import 'package:analyzer/src/generated/java_engine.dart' show Predicate;
14 import 'package:analyzer/src/generated/scanner.dart'; 14 import 'package:analyzer/src/generated/scanner.dart';
15 import 'package:analyzer/src/generated/ast.dart'; 15 import 'package:analyzer/src/generated/ast.dart';
16 import 'package:analyzer/src/generated/utilities_dart.dart';
17 import 'package:analyzer/src/generated/element.dart' show ClassElement;
18 import 'package:unittest/unittest.dart' as _ut; 16 import 'package:unittest/unittest.dart' as _ut;
19 import 'parser_test.dart' show ParserTestCase; 17 import 'parser_test.dart' show ParserTestCase;
20 import 'test_support.dart'; 18 import 'test_support.dart';
21 import 'scanner_test.dart' show TokenFactory; 19 import 'package:analyzer/src/generated/testing/ast_factory.dart';
20 import 'package:analyzer/src/generated/testing/token_factory.dart';
22 21
23 class AssignmentKind extends Enum<AssignmentKind> { 22 class AssignmentKind extends Enum<AssignmentKind> {
24 static const AssignmentKind BINARY = const AssignmentKind('BINARY', 0); 23 static const AssignmentKind BINARY = const AssignmentKind('BINARY', 0);
25 24
26 static const AssignmentKind COMPOUND_LEFT = const AssignmentKind('COMPOUND_LEF T', 1); 25 static const AssignmentKind COMPOUND_LEFT = const AssignmentKind('COMPOUND_LEF T', 1);
27 26
28 static const AssignmentKind COMPOUND_RIGHT = const AssignmentKind('COMPOUND_RI GHT', 2); 27 static const AssignmentKind COMPOUND_RIGHT = const AssignmentKind('COMPOUND_RI GHT', 2);
29 28
30 static const AssignmentKind POSTFIX_INC = const AssignmentKind('POSTFIX_INC', 3); 29 static const AssignmentKind POSTFIX_INC = const AssignmentKind('POSTFIX_INC', 3);
31 30
(...skipping 17 matching lines...) Expand all
49 PREFIX_DEC, 48 PREFIX_DEC,
50 PREFIX_INC, 49 PREFIX_INC,
51 PREFIX_NOT, 50 PREFIX_NOT,
52 SIMPLE_LEFT, 51 SIMPLE_LEFT,
53 SIMPLE_RIGHT, 52 SIMPLE_RIGHT,
54 NONE]; 53 NONE];
55 54
56 const AssignmentKind(String name, int ordinal) : super(name, ordinal); 55 const AssignmentKind(String name, int ordinal) : super(name, ordinal);
57 } 56 }
58 57
59 /**
60 * The class `AstFactory` defines utility methods that can be used to create AST nodes. The
61 * nodes that are created are complete in the sense that all of the tokens that would have been
62 * associated with the nodes by a parser are also created, but the token stream is not constructed.
63 * None of the nodes are resolved.
64 *
65 * The general pattern is for the name of the factory method to be the same as t he name of the class
66 * of AST node being created. There are two notable exceptions. The first is for methods creating
67 * nodes that are part of a cascade expression. These methods are all prefixed w ith 'cascaded'. The
68 * second is places where a shorter name seemed unambiguous and easier to read, such as using
69 * 'identifier' rather than 'prefixedIdentifier', or 'integer' rather than 'inte gerLiteral'.
70 */
71 class AstFactory {
72 static AdjacentStrings adjacentStrings(List<StringLiteral> strings) => new Adj acentStrings(list(strings));
73
74 static Annotation annotation(Identifier name) => new Annotation(TokenFactory.t okenFromType(TokenType.AT), name, null, null, null);
75
76 static Annotation annotation2(Identifier name, SimpleIdentifier constructorNam e, ArgumentList arguments) => new Annotation(TokenFactory.tokenFromType(TokenTyp e.AT), name, TokenFactory.tokenFromType(TokenType.PERIOD), constructorName, argu ments);
77
78 static ArgumentList argumentList(List<Expression> arguments) => new ArgumentLi st(TokenFactory.tokenFromType(TokenType.OPEN_PAREN), list(arguments), TokenFacto ry.tokenFromType(TokenType.CLOSE_PAREN));
79
80 static AsExpression asExpression(Expression expression, TypeName type) => new AsExpression(expression, TokenFactory.tokenFromKeyword(Keyword.AS), type);
81
82 static AssertStatement assertStatement(Expression condition) => new AssertStat ement(TokenFactory.tokenFromKeyword(Keyword.ASSERT), TokenFactory.tokenFromType( TokenType.OPEN_PAREN), condition, TokenFactory.tokenFromType(TokenType.CLOSE_PAR EN), TokenFactory.tokenFromType(TokenType.SEMICOLON));
83
84 static AssignmentExpression assignmentExpression(Expression leftHandSide, Toke nType operator, Expression rightHandSide) => new AssignmentExpression(leftHandSi de, TokenFactory.tokenFromType(operator), rightHandSide);
85
86 static BinaryExpression binaryExpression(Expression leftOperand, TokenType ope rator, Expression rightOperand) => new BinaryExpression(leftOperand, TokenFactor y.tokenFromType(operator), rightOperand);
87
88 static Block block(List<Statement> statements) => new Block(TokenFactory.token FromType(TokenType.OPEN_CURLY_BRACKET), list(statements), TokenFactory.tokenFrom Type(TokenType.CLOSE_CURLY_BRACKET));
89
90 static BlockFunctionBody blockFunctionBody(Block block) => new BlockFunctionBo dy(block);
91
92 static BlockFunctionBody blockFunctionBody2(List<Statement> statements) => new BlockFunctionBody(block(statements));
93
94 static BooleanLiteral booleanLiteral(bool value) => new BooleanLiteral(value ? TokenFactory.tokenFromKeyword(Keyword.TRUE) : TokenFactory.tokenFromKeyword(Key word.FALSE), value);
95
96 static BreakStatement breakStatement() => new BreakStatement(TokenFactory.toke nFromKeyword(Keyword.BREAK), null, TokenFactory.tokenFromType(TokenType.SEMICOLO N));
97
98 static BreakStatement breakStatement2(String label) => new BreakStatement(Toke nFactory.tokenFromKeyword(Keyword.BREAK), identifier3(label), TokenFactory.token FromType(TokenType.SEMICOLON));
99
100 static IndexExpression cascadedIndexExpression(Expression index) => new IndexE xpression.forCascade(TokenFactory.tokenFromType(TokenType.PERIOD_PERIOD), TokenF actory.tokenFromType(TokenType.OPEN_SQUARE_BRACKET), index, TokenFactory.tokenFr omType(TokenType.CLOSE_SQUARE_BRACKET));
101
102 static MethodInvocation cascadedMethodInvocation(String methodName, List<Expre ssion> arguments) => new MethodInvocation(null, TokenFactory.tokenFromType(Token Type.PERIOD_PERIOD), identifier3(methodName), argumentList(arguments));
103
104 static PropertyAccess cascadedPropertyAccess(String propertyName) => new Prope rtyAccess(null, TokenFactory.tokenFromType(TokenType.PERIOD_PERIOD), identifier3 (propertyName));
105
106 static CascadeExpression cascadeExpression(Expression target, List<Expression> cascadeSections) => new CascadeExpression(target, list(cascadeSections));
107
108 static CatchClause catchClause(String exceptionParameter, List<Statement> stat ements) => catchClause5(null, exceptionParameter, null, statements);
109
110 static CatchClause catchClause2(String exceptionParameter, String stackTracePa rameter, List<Statement> statements) => catchClause5(null, exceptionParameter, s tackTraceParameter, statements);
111
112 static CatchClause catchClause3(TypeName exceptionType, List<Statement> statem ents) => catchClause5(exceptionType, null, null, statements);
113
114 static CatchClause catchClause4(TypeName exceptionType, String exceptionParame ter, List<Statement> statements) => catchClause5(exceptionType, exceptionParamet er, null, statements);
115
116 static CatchClause catchClause5(TypeName exceptionType, String exceptionParame ter, String stackTraceParameter, List<Statement> statements) => new CatchClause( exceptionType == null ? null : TokenFactory.tokenFromTypeAndString(TokenType.IDE NTIFIER, "on"), exceptionType, exceptionParameter == null ? null : TokenFactory. tokenFromKeyword(Keyword.CATCH), exceptionParameter == null ? null : TokenFactor y.tokenFromType(TokenType.OPEN_PAREN), exceptionParameter == null ? null : ident ifier3(exceptionParameter), stackTraceParameter == null ? null : TokenFactory.to kenFromType(TokenType.COMMA), stackTraceParameter == null ? null : identifier3(s tackTraceParameter), exceptionParameter == null ? null : TokenFactory.tokenFromT ype(TokenType.CLOSE_PAREN), block(statements));
117
118 static ClassDeclaration classDeclaration(Keyword abstractKeyword, String name, TypeParameterList typeParameters, ExtendsClause extendsClause, WithClause withC lause, ImplementsClause implementsClause, List<ClassMember> members) => new Clas sDeclaration(null, null, abstractKeyword == null ? null : TokenFactory.tokenFrom Keyword(abstractKeyword), TokenFactory.tokenFromKeyword(Keyword.CLASS), identifi er3(name), typeParameters, extendsClause, withClause, implementsClause, TokenFac tory.tokenFromType(TokenType.OPEN_CURLY_BRACKET), list(members), TokenFactory.to kenFromType(TokenType.CLOSE_CURLY_BRACKET));
119
120 static ClassTypeAlias classTypeAlias(String name, TypeParameterList typeParame ters, Keyword abstractKeyword, TypeName superclass, WithClause withClause, Imple mentsClause implementsClause) => new ClassTypeAlias(null, null, TokenFactory.tok enFromKeyword(Keyword.CLASS), identifier3(name), typeParameters, TokenFactory.to kenFromType(TokenType.EQ), abstractKeyword == null ? null : TokenFactory.tokenFr omKeyword(abstractKeyword), superclass, withClause, implementsClause, TokenFacto ry.tokenFromType(TokenType.SEMICOLON));
121
122 static CompilationUnit compilationUnit() => compilationUnit8(null, null, null) ;
123
124 static CompilationUnit compilationUnit2(List<CompilationUnitMember> declaratio ns) => compilationUnit8(null, null, list(declarations));
125
126 static CompilationUnit compilationUnit3(List<Directive> directives) => compila tionUnit8(null, list(directives), null);
127
128 static CompilationUnit compilationUnit4(List<Directive> directives, List<Compi lationUnitMember> declarations) => compilationUnit8(null, directives, declaratio ns);
129
130 static CompilationUnit compilationUnit5(String scriptTag) => compilationUnit8( scriptTag, null, null);
131
132 static CompilationUnit compilationUnit6(String scriptTag, List<CompilationUnit Member> declarations) => compilationUnit8(scriptTag, null, list(declarations));
133
134 static CompilationUnit compilationUnit7(String scriptTag, List<Directive> dire ctives) => compilationUnit8(scriptTag, list(directives), null);
135
136 static CompilationUnit compilationUnit8(String scriptTag, List<Directive> dire ctives, List<CompilationUnitMember> declarations) => new CompilationUnit(TokenFa ctory.tokenFromType(TokenType.EOF), scriptTag == null ? null : AstFactory.script Tag(scriptTag), directives == null ? new List<Directive>() : directives, declara tions == null ? new List<CompilationUnitMember>() : declarations, TokenFactory.t okenFromType(TokenType.EOF));
137
138 static ConditionalExpression conditionalExpression(Expression condition, Expre ssion thenExpression, Expression elseExpression) => new ConditionalExpression(co ndition, TokenFactory.tokenFromType(TokenType.QUESTION), thenExpression, TokenFa ctory.tokenFromType(TokenType.COLON), elseExpression);
139
140 static ConstructorDeclaration constructorDeclaration(Identifier returnType, St ring name, FormalParameterList parameters, List<ConstructorInitializer> initiali zers) => new ConstructorDeclaration(null, null, TokenFactory.tokenFromKeyword(Ke yword.EXTERNAL), null, null, returnType, name == null ? null : TokenFactory.toke nFromType(TokenType.PERIOD), name == null ? null : identifier3(name), parameters , initializers == null || initializers.isEmpty ? null : TokenFactory.tokenFromTy pe(TokenType.PERIOD), initializers == null ? new List<ConstructorInitializer>() : initializers, null, emptyFunctionBody());
141
142 static ConstructorDeclaration constructorDeclaration2(Keyword constKeyword, Ke yword factoryKeyword, Identifier returnType, String name, FormalParameterList pa rameters, List<ConstructorInitializer> initializers, FunctionBody body) => new C onstructorDeclaration(null, null, null, constKeyword == null ? null : TokenFacto ry.tokenFromKeyword(constKeyword), factoryKeyword == null ? null : TokenFactory. tokenFromKeyword(factoryKeyword), returnType, name == null ? null : TokenFactory .tokenFromType(TokenType.PERIOD), name == null ? null : identifier3(name), param eters, initializers == null || initializers.isEmpty ? null : TokenFactory.tokenF romType(TokenType.PERIOD), initializers == null ? new List<ConstructorInitialize r>() : initializers, null, body);
143
144 static ConstructorFieldInitializer constructorFieldInitializer(bool prefixedWi thThis, String fieldName, Expression expression) => new ConstructorFieldInitiali zer(prefixedWithThis ? TokenFactory.tokenFromKeyword(Keyword.THIS) : null, prefi xedWithThis ? TokenFactory.tokenFromType(TokenType.PERIOD) : null, identifier3(f ieldName), TokenFactory.tokenFromType(TokenType.EQ), expression);
145
146 static ConstructorName constructorName(TypeName type, String name) => new Cons tructorName(type, name == null ? null : TokenFactory.tokenFromType(TokenType.PER IOD), name == null ? null : identifier3(name));
147
148 static ContinueStatement continueStatement([String label]) {
149 SimpleIdentifier labelNode = label == null ? null : identifier3(label);
150 return new ContinueStatement(TokenFactory.tokenFromKeyword(Keyword.CONTINUE) , labelNode, TokenFactory.tokenFromType(TokenType.SEMICOLON));
151 }
152
153 static DeclaredIdentifier declaredIdentifier(Keyword keyword, String identifie r) => declaredIdentifier2(keyword, null, identifier);
154
155 static DeclaredIdentifier declaredIdentifier2(Keyword keyword, TypeName type, String identifier) => new DeclaredIdentifier(null, null, keyword == null ? null : TokenFactory.tokenFromKeyword(keyword), type, identifier3(identifier));
156
157 static DeclaredIdentifier declaredIdentifier3(String identifier) => declaredId entifier2(null, null, identifier);
158
159 static DeclaredIdentifier declaredIdentifier4(TypeName type, String identifier ) => declaredIdentifier2(null, type, identifier);
160
161 static DoStatement doStatement(Statement body, Expression condition) => new Do Statement(TokenFactory.tokenFromKeyword(Keyword.DO), body, TokenFactory.tokenFro mKeyword(Keyword.WHILE), TokenFactory.tokenFromType(TokenType.OPEN_PAREN), condi tion, TokenFactory.tokenFromType(TokenType.CLOSE_PAREN), TokenFactory.tokenFromT ype(TokenType.SEMICOLON));
162
163 static DoubleLiteral doubleLiteral(double value) => new DoubleLiteral(TokenFac tory.tokenFromString(value.toString()), value);
164
165 static EmptyFunctionBody emptyFunctionBody() => new EmptyFunctionBody(TokenFac tory.tokenFromType(TokenType.SEMICOLON));
166
167 static EmptyStatement emptyStatement() => new EmptyStatement(TokenFactory.toke nFromType(TokenType.SEMICOLON));
168
169 static ExportDirective exportDirective(List<Annotation> metadata, String uri, List<Combinator> combinators) => new ExportDirective(null, metadata, TokenFactor y.tokenFromKeyword(Keyword.EXPORT), string2(uri), list(combinators), TokenFactor y.tokenFromType(TokenType.SEMICOLON));
170
171 static ExportDirective exportDirective2(String uri, List<Combinator> combinato rs) => exportDirective(new List<Annotation>(), uri, combinators);
172
173 static ExpressionFunctionBody expressionFunctionBody(Expression expression) => new ExpressionFunctionBody(TokenFactory.tokenFromType(TokenType.FUNCTION), expr ession, TokenFactory.tokenFromType(TokenType.SEMICOLON));
174
175 static ExpressionStatement expressionStatement(Expression expression) => new E xpressionStatement(expression, TokenFactory.tokenFromType(TokenType.SEMICOLON));
176
177 static ExtendsClause extendsClause(TypeName type) => new ExtendsClause(TokenFa ctory.tokenFromKeyword(Keyword.EXTENDS), type);
178
179 static FieldDeclaration fieldDeclaration(bool isStatic, Keyword keyword, TypeN ame type, List<VariableDeclaration> variables) => new FieldDeclaration(null, nul l, isStatic ? TokenFactory.tokenFromKeyword(Keyword.STATIC) : null, variableDecl arationList(keyword, type, variables), TokenFactory.tokenFromType(TokenType.SEMI COLON));
180
181 static FieldDeclaration fieldDeclaration2(bool isStatic, Keyword keyword, List <VariableDeclaration> variables) => fieldDeclaration(isStatic, keyword, null, va riables);
182
183 static FieldFormalParameter fieldFormalParameter(Keyword keyword, TypeName typ e, String identifier, [FormalParameterList parameterList]) => new FieldFormalPar ameter(null, null, keyword == null ? null : TokenFactory.tokenFromKeyword(keywor d), type, TokenFactory.tokenFromKeyword(Keyword.THIS), TokenFactory.tokenFromTyp e(TokenType.PERIOD), identifier3(identifier), parameterList);
184
185 static FieldFormalParameter fieldFormalParameter2(String identifier) => fieldF ormalParameter(null, null, identifier);
186
187 static ForEachStatement forEachStatement(DeclaredIdentifier loopVariable, Expr ession iterator, Statement body) => new ForEachStatement.con1(TokenFactory.token FromKeyword(Keyword.FOR), TokenFactory.tokenFromType(TokenType.OPEN_PAREN), loop Variable, TokenFactory.tokenFromKeyword(Keyword.IN), iterator, TokenFactory.toke nFromType(TokenType.CLOSE_PAREN), body);
188
189 static ForEachStatement forEachStatement2(SimpleIdentifier identifier, Express ion iterator, Statement body) => new ForEachStatement.con2(TokenFactory.tokenFro mKeyword(Keyword.FOR), TokenFactory.tokenFromType(TokenType.OPEN_PAREN), identif ier, TokenFactory.tokenFromKeyword(Keyword.IN), iterator, TokenFactory.tokenFrom Type(TokenType.CLOSE_PAREN), body);
190
191 static FormalParameterList formalParameterList(List<FormalParameter> parameter s) => new FormalParameterList(TokenFactory.tokenFromType(TokenType.OPEN_PAREN), list(parameters), null, null, TokenFactory.tokenFromType(TokenType.CLOSE_PAREN)) ;
192
193 static ForStatement forStatement(Expression initialization, Expression conditi on, List<Expression> updaters, Statement body) => new ForStatement(TokenFactory. tokenFromKeyword(Keyword.FOR), TokenFactory.tokenFromType(TokenType.OPEN_PAREN), null, initialization, TokenFactory.tokenFromType(TokenType.SEMICOLON), conditio n, TokenFactory.tokenFromType(TokenType.SEMICOLON), updaters, TokenFactory.token FromType(TokenType.CLOSE_PAREN), body);
194
195 static ForStatement forStatement2(VariableDeclarationList variableList, Expres sion condition, List<Expression> updaters, Statement body) => new ForStatement(T okenFactory.tokenFromKeyword(Keyword.FOR), TokenFactory.tokenFromType(TokenType. OPEN_PAREN), variableList, null, TokenFactory.tokenFromType(TokenType.SEMICOLON) , condition, TokenFactory.tokenFromType(TokenType.SEMICOLON), updaters, TokenFac tory.tokenFromType(TokenType.CLOSE_PAREN), body);
196
197 static FunctionDeclaration functionDeclaration(TypeName type, Keyword keyword, String name, FunctionExpression functionExpression) => new FunctionDeclaration( null, null, null, type, keyword == null ? null : TokenFactory.tokenFromKeyword(k eyword), identifier3(name), functionExpression);
198
199 static FunctionDeclarationStatement functionDeclarationStatement(TypeName type , Keyword keyword, String name, FunctionExpression functionExpression) => new Fu nctionDeclarationStatement(functionDeclaration(type, keyword, name, functionExpr ession));
200
201 static FunctionExpression functionExpression() => new FunctionExpression(forma lParameterList([]), blockFunctionBody2([]));
202
203 static FunctionExpression functionExpression2(FormalParameterList parameters, FunctionBody body) => new FunctionExpression(parameters, body);
204
205 static FunctionExpressionInvocation functionExpressionInvocation(Expression fu nction, List<Expression> arguments) => new FunctionExpressionInvocation(function , argumentList(arguments));
206
207 static FunctionTypedFormalParameter functionTypedFormalParameter(TypeName retu rnType, String identifier, List<FormalParameter> parameters) => new FunctionType dFormalParameter(null, null, returnType, identifier3(identifier), formalParamete rList(parameters));
208
209 static HideCombinator hideCombinator(List<SimpleIdentifier> identifiers) => ne w HideCombinator(TokenFactory.tokenFromString("hide"), list(identifiers));
210
211 static HideCombinator hideCombinator2(List<String> identifiers) {
212 List<SimpleIdentifier> identifierList = new List<SimpleIdentifier>();
213 for (String identifier in identifiers) {
214 identifierList.add(identifier3(identifier));
215 }
216 return new HideCombinator(TokenFactory.tokenFromString("hide"), identifierLi st);
217 }
218
219 static PrefixedIdentifier identifier(SimpleIdentifier prefix, SimpleIdentifier identifier) => new PrefixedIdentifier(prefix, TokenFactory.tokenFromType(TokenT ype.PERIOD), identifier);
220
221 static SimpleIdentifier identifier3(String lexeme) => new SimpleIdentifier(Tok enFactory.tokenFromTypeAndString(TokenType.IDENTIFIER, lexeme));
222
223 static PrefixedIdentifier identifier4(String prefix, SimpleIdentifier identifi er) => new PrefixedIdentifier(identifier3(prefix), TokenFactory.tokenFromType(To kenType.PERIOD), identifier);
224
225 static PrefixedIdentifier identifier5(String prefix, String identifier) => new PrefixedIdentifier(identifier3(prefix), TokenFactory.tokenFromType(TokenType.PE RIOD), identifier3(identifier));
226
227 static IfStatement ifStatement(Expression condition, Statement thenStatement) => ifStatement2(condition, thenStatement, null);
228
229 static IfStatement ifStatement2(Expression condition, Statement thenStatement, Statement elseStatement) => new IfStatement(TokenFactory.tokenFromKeyword(Keywo rd.IF), TokenFactory.tokenFromType(TokenType.OPEN_PAREN), condition, TokenFactor y.tokenFromType(TokenType.CLOSE_PAREN), thenStatement, elseStatement == null ? n ull : TokenFactory.tokenFromKeyword(Keyword.ELSE), elseStatement);
230
231 static ImplementsClause implementsClause(List<TypeName> types) => new Implemen tsClause(TokenFactory.tokenFromKeyword(Keyword.IMPLEMENTS), list(types));
232
233 static ImportDirective importDirective(List<Annotation> metadata, String uri, bool isDeferred, String prefix, List<Combinator> combinators) => new ImportDirec tive(null, metadata, TokenFactory.tokenFromKeyword(Keyword.IMPORT), string2(uri) , !isDeferred ? null : TokenFactory.tokenFromKeyword(Keyword.DEFERRED), prefix = = null ? null : TokenFactory.tokenFromKeyword(Keyword.AS), prefix == null ? null : identifier3(prefix), list(combinators), TokenFactory.tokenFromType(TokenType. SEMICOLON));
234
235 static ImportDirective importDirective2(String uri, bool isDeferred, String pr efix, List<Combinator> combinators) => importDirective(new List<Annotation>(), u ri, isDeferred, prefix, combinators);
236
237 static ImportDirective importDirective3(String uri, String prefix, List<Combin ator> combinators) => importDirective(new List<Annotation>(), uri, false, prefix , combinators);
238
239 static IndexExpression indexExpression(Expression array, Expression index) => new IndexExpression.forTarget(array, TokenFactory.tokenFromType(TokenType.OPEN_S QUARE_BRACKET), index, TokenFactory.tokenFromType(TokenType.CLOSE_SQUARE_BRACKET ));
240
241 static InstanceCreationExpression instanceCreationExpression(Keyword keyword, ConstructorName name, List<Expression> arguments) => new InstanceCreationExpress ion(keyword == null ? null : TokenFactory.tokenFromKeyword(keyword), name, argum entList(arguments));
242
243 static InstanceCreationExpression instanceCreationExpression2(Keyword keyword, TypeName type, List<Expression> arguments) => instanceCreationExpression3(keywo rd, type, null, arguments);
244
245 static InstanceCreationExpression instanceCreationExpression3(Keyword keyword, TypeName type, String identifier, List<Expression> arguments) => instanceCreati onExpression(keyword, new ConstructorName(type, identifier == null ? null : Toke nFactory.tokenFromType(TokenType.PERIOD), identifier == null ? null : identifier 3(identifier)), arguments);
246
247 static IntegerLiteral integer(int value) => new IntegerLiteral(TokenFactory.to kenFromTypeAndString(TokenType.INT, value.toString()), value);
248
249 static InterpolationExpression interpolationExpression(Expression expression) => new InterpolationExpression(TokenFactory.tokenFromType(TokenType.STRING_INTER POLATION_EXPRESSION), expression, TokenFactory.tokenFromType(TokenType.CLOSE_CUR LY_BRACKET));
250
251 static InterpolationExpression interpolationExpression2(String identifier) => new InterpolationExpression(TokenFactory.tokenFromType(TokenType.STRING_INTERPOL ATION_IDENTIFIER), identifier3(identifier), null);
252
253 static InterpolationString interpolationString(String contents, String value) => new InterpolationString(TokenFactory.tokenFromString(contents), value);
254
255 static IsExpression isExpression(Expression expression, bool negated, TypeName type) => new IsExpression(expression, TokenFactory.tokenFromKeyword(Keyword.IS) , negated ? TokenFactory.tokenFromType(TokenType.BANG) : null, type);
256
257 static Label label(SimpleIdentifier label) => new Label(label, TokenFactory.to kenFromType(TokenType.COLON));
258
259 static Label label2(String label) => AstFactory.label(identifier3(label));
260
261 static LabeledStatement labeledStatement(List<Label> labels, Statement stateme nt) => new LabeledStatement(labels, statement);
262
263 static LibraryDirective libraryDirective(List<Annotation> metadata, LibraryIde ntifier libraryName) => new LibraryDirective(null, metadata, TokenFactory.tokenF romKeyword(Keyword.LIBRARY), libraryName, TokenFactory.tokenFromType(TokenType.S EMICOLON));
264
265 static LibraryDirective libraryDirective2(String libraryName) => libraryDirect ive(new List<Annotation>(), libraryIdentifier2([libraryName]));
266
267 static LibraryIdentifier libraryIdentifier(List<SimpleIdentifier> components) => new LibraryIdentifier(list(components));
268
269 static LibraryIdentifier libraryIdentifier2(List<String> components) {
270 List<SimpleIdentifier> componentList = new List<SimpleIdentifier>();
271 for (String component in components) {
272 componentList.add(identifier3(component));
273 }
274 return new LibraryIdentifier(componentList);
275 }
276
277 static List list(List<Object> elements) {
278 List elementList = new List();
279 for (Object element in elements) {
280 elementList.add(element);
281 }
282 return elementList;
283 }
284
285 static ListLiteral listLiteral(List<Expression> elements) => listLiteral2(null , null, elements);
286
287 static ListLiteral listLiteral2(Keyword keyword, TypeArgumentList typeArgument s, List<Expression> elements) => new ListLiteral(keyword == null ? null : TokenF actory.tokenFromKeyword(keyword), typeArguments, TokenFactory.tokenFromType(Toke nType.OPEN_SQUARE_BRACKET), list(elements), TokenFactory.tokenFromType(TokenType .CLOSE_SQUARE_BRACKET));
288
289 static MapLiteral mapLiteral(Keyword keyword, TypeArgumentList typeArguments, List<MapLiteralEntry> entries) => new MapLiteral(keyword == null ? null : TokenF actory.tokenFromKeyword(keyword), typeArguments, TokenFactory.tokenFromType(Toke nType.OPEN_CURLY_BRACKET), list(entries), TokenFactory.tokenFromType(TokenType.C LOSE_CURLY_BRACKET));
290
291 static MapLiteral mapLiteral2(List<MapLiteralEntry> entries) => mapLiteral(nul l, null, entries);
292
293 static MapLiteralEntry mapLiteralEntry(String key, Expression value) => new Ma pLiteralEntry(string2(key), TokenFactory.tokenFromType(TokenType.COLON), value);
294
295 static MethodDeclaration methodDeclaration(Keyword modifier, TypeName returnTy pe, Keyword property, Keyword operator, SimpleIdentifier name, FormalParameterLi st parameters) => new MethodDeclaration(null, null, TokenFactory.tokenFromKeywor d(Keyword.EXTERNAL), modifier == null ? null : TokenFactory.tokenFromKeyword(mod ifier), returnType, property == null ? null : TokenFactory.tokenFromKeyword(prop erty), operator == null ? null : TokenFactory.tokenFromKeyword(operator), name, parameters, emptyFunctionBody());
296
297 static MethodDeclaration methodDeclaration2(Keyword modifier, TypeName returnT ype, Keyword property, Keyword operator, SimpleIdentifier name, FormalParameterL ist parameters, FunctionBody body) => new MethodDeclaration(null, null, null, mo difier == null ? null : TokenFactory.tokenFromKeyword(modifier), returnType, pro perty == null ? null : TokenFactory.tokenFromKeyword(property), operator == null ? null : TokenFactory.tokenFromKeyword(operator), name, parameters, body);
298
299 static MethodInvocation methodInvocation(Expression target, String methodName, List<Expression> arguments) => new MethodInvocation(target, target == null ? nu ll : TokenFactory.tokenFromType(TokenType.PERIOD), identifier3(methodName), argu mentList(arguments));
300
301 static MethodInvocation methodInvocation2(String methodName, List<Expression> arguments) => methodInvocation(null, methodName, arguments);
302
303 static NamedExpression namedExpression(Label label, Expression expression) => new NamedExpression(label, expression);
304
305 static NamedExpression namedExpression2(String label, Expression expression) = > namedExpression(label2(label), expression);
306
307 static DefaultFormalParameter namedFormalParameter(NormalFormalParameter param eter, Expression expression) => new DefaultFormalParameter(parameter, ParameterK ind.NAMED, expression == null ? null : TokenFactory.tokenFromType(TokenType.COLO N), expression);
308
309 static NativeClause nativeClause(String nativeCode) => new NativeClause(TokenF actory.tokenFromString("native"), string2(nativeCode));
310
311 static NativeFunctionBody nativeFunctionBody(String nativeMethodName) => new N ativeFunctionBody(TokenFactory.tokenFromString("native"), string2(nativeMethodNa me), TokenFactory.tokenFromType(TokenType.SEMICOLON));
312
313 static NullLiteral nullLiteral() => new NullLiteral(TokenFactory.tokenFromKeyw ord(Keyword.NULL));
314
315 static ParenthesizedExpression parenthesizedExpression(Expression expression) => new ParenthesizedExpression(TokenFactory.tokenFromType(TokenType.OPEN_PAREN), expression, TokenFactory.tokenFromType(TokenType.CLOSE_PAREN));
316
317 static PartDirective partDirective(List<Annotation> metadata, String url) => n ew PartDirective(null, metadata, TokenFactory.tokenFromKeyword(Keyword.PART), st ring2(url), TokenFactory.tokenFromType(TokenType.SEMICOLON));
318
319 static PartDirective partDirective2(String url) => partDirective(new List<Anno tation>(), url);
320
321 static PartOfDirective partOfDirective(LibraryIdentifier libraryName) => partO fDirective2(new List<Annotation>(), libraryName);
322
323 static PartOfDirective partOfDirective2(List<Annotation> metadata, LibraryIden tifier libraryName) => new PartOfDirective(null, metadata, TokenFactory.tokenFro mKeyword(Keyword.PART), TokenFactory.tokenFromString("of"), libraryName, TokenFa ctory.tokenFromType(TokenType.SEMICOLON));
324
325 static DefaultFormalParameter positionalFormalParameter(NormalFormalParameter parameter, Expression expression) => new DefaultFormalParameter(parameter, Param eterKind.POSITIONAL, expression == null ? null : TokenFactory.tokenFromType(Toke nType.EQ), expression);
326
327 static PostfixExpression postfixExpression(Expression expression, TokenType op erator) => new PostfixExpression(expression, TokenFactory.tokenFromType(operator ));
328
329 static PrefixExpression prefixExpression(TokenType operator, Expression expres sion) => new PrefixExpression(TokenFactory.tokenFromType(operator), expression);
330
331 static PropertyAccess propertyAccess(Expression target, SimpleIdentifier prope rtyName) => new PropertyAccess(target, TokenFactory.tokenFromType(TokenType.PERI OD), propertyName);
332
333 static PropertyAccess propertyAccess2(Expression target, String propertyName) => new PropertyAccess(target, TokenFactory.tokenFromType(TokenType.PERIOD), iden tifier3(propertyName));
334
335 static RedirectingConstructorInvocation redirectingConstructorInvocation(List< Expression> arguments) => redirectingConstructorInvocation2(null, arguments);
336
337 static RedirectingConstructorInvocation redirectingConstructorInvocation2(Stri ng constructorName, List<Expression> arguments) => new RedirectingConstructorInv ocation(TokenFactory.tokenFromKeyword(Keyword.THIS), constructorName == null ? n ull : TokenFactory.tokenFromType(TokenType.PERIOD), constructorName == null ? nu ll : identifier3(constructorName), argumentList(arguments));
338
339 static RethrowExpression rethrowExpression() => new RethrowExpression(TokenFac tory.tokenFromKeyword(Keyword.RETHROW));
340
341 static ReturnStatement returnStatement() => returnStatement2(null);
342
343 static ReturnStatement returnStatement2(Expression expression) => new ReturnSt atement(TokenFactory.tokenFromKeyword(Keyword.RETURN), expression, TokenFactory. tokenFromType(TokenType.SEMICOLON));
344
345 static ScriptTag scriptTag(String scriptTag) => new ScriptTag(TokenFactory.tok enFromString(scriptTag));
346
347 static ShowCombinator showCombinator(List<SimpleIdentifier> identifiers) => ne w ShowCombinator(TokenFactory.tokenFromString("show"), list(identifiers));
348
349 static ShowCombinator showCombinator2(List<String> identifiers) {
350 List<SimpleIdentifier> identifierList = new List<SimpleIdentifier>();
351 for (String identifier in identifiers) {
352 identifierList.add(identifier3(identifier));
353 }
354 return new ShowCombinator(TokenFactory.tokenFromString("show"), identifierLi st);
355 }
356
357 static SimpleFormalParameter simpleFormalParameter(Keyword keyword, String par ameterName) => simpleFormalParameter2(keyword, null, parameterName);
358
359 static SimpleFormalParameter simpleFormalParameter2(Keyword keyword, TypeName type, String parameterName) => new SimpleFormalParameter(null, null, keyword == null ? null : TokenFactory.tokenFromKeyword(keyword), type, identifier3(paramete rName));
360
361 static SimpleFormalParameter simpleFormalParameter3(String parameterName) => s impleFormalParameter2(null, null, parameterName);
362
363 static SimpleFormalParameter simpleFormalParameter4(TypeName type, String para meterName) => simpleFormalParameter2(null, type, parameterName);
364
365 static StringInterpolation string(List<InterpolationElement> elements) => new StringInterpolation(list(elements));
366
367 static SimpleStringLiteral string2(String content) => new SimpleStringLiteral( TokenFactory.tokenFromString("'${content}'"), content);
368
369 static SuperConstructorInvocation superConstructorInvocation(List<Expression> arguments) => superConstructorInvocation2(null, arguments);
370
371 static SuperConstructorInvocation superConstructorInvocation2(String name, Lis t<Expression> arguments) => new SuperConstructorInvocation(TokenFactory.tokenFro mKeyword(Keyword.SUPER), name == null ? null : TokenFactory.tokenFromType(TokenT ype.PERIOD), name == null ? null : identifier3(name), argumentList(arguments));
372
373 static SuperExpression superExpression() => new SuperExpression(TokenFactory.t okenFromKeyword(Keyword.SUPER));
374
375 static SwitchCase switchCase(Expression expression, List<Statement> statements ) => switchCase2(new List<Label>(), expression, statements);
376
377 static SwitchCase switchCase2(List<Label> labels, Expression expression, List< Statement> statements) => new SwitchCase(labels, TokenFactory.tokenFromKeyword(K eyword.CASE), expression, TokenFactory.tokenFromType(TokenType.COLON), list(stat ements));
378
379 static SwitchDefault switchDefault(List<Label> labels, List<Statement> stateme nts) => new SwitchDefault(labels, TokenFactory.tokenFromKeyword(Keyword.DEFAULT) , TokenFactory.tokenFromType(TokenType.COLON), list(statements));
380
381 static SwitchDefault switchDefault2(List<Statement> statements) => switchDefau lt(new List<Label>(), statements);
382
383 static SwitchStatement switchStatement(Expression expression, List<SwitchMembe r> members) => new SwitchStatement(TokenFactory.tokenFromKeyword(Keyword.SWITCH) , TokenFactory.tokenFromType(TokenType.OPEN_PAREN), expression, TokenFactory.tok enFromType(TokenType.CLOSE_PAREN), TokenFactory.tokenFromType(TokenType.OPEN_CUR LY_BRACKET), list(members), TokenFactory.tokenFromType(TokenType.CLOSE_CURLY_BRA CKET));
384
385 static SymbolLiteral symbolLiteral(List<String> components) {
386 List<Token> identifierList = new List<Token>();
387 for (String component in components) {
388 identifierList.add(TokenFactory.tokenFromTypeAndString(TokenType.IDENTIFIE R, component));
389 }
390 return new SymbolLiteral(TokenFactory.tokenFromType(TokenType.HASH), new Lis t.from(identifierList));
391 }
392
393 static ThisExpression thisExpression() => new ThisExpression(TokenFactory.toke nFromKeyword(Keyword.THIS));
394
395 static ThrowExpression throwExpression() => throwExpression2(null);
396
397 static ThrowExpression throwExpression2(Expression expression) => new ThrowExp ression(TokenFactory.tokenFromKeyword(Keyword.THROW), expression);
398
399 static TopLevelVariableDeclaration topLevelVariableDeclaration(Keyword keyword , TypeName type, List<VariableDeclaration> variables) => new TopLevelVariableDec laration(null, null, variableDeclarationList(keyword, type, variables), TokenFac tory.tokenFromType(TokenType.SEMICOLON));
400
401 static TopLevelVariableDeclaration topLevelVariableDeclaration2(Keyword keywor d, List<VariableDeclaration> variables) => new TopLevelVariableDeclaration(null, null, variableDeclarationList(keyword, null, variables), TokenFactory.tokenFrom Type(TokenType.SEMICOLON));
402
403 static TryStatement tryStatement(Block body, Block finallyClause) => tryStatem ent3(body, new List<CatchClause>(), finallyClause);
404
405 static TryStatement tryStatement2(Block body, List<CatchClause> catchClauses) => tryStatement3(body, list(catchClauses), null);
406
407 static TryStatement tryStatement3(Block body, List<CatchClause> catchClauses, Block finallyClause) => new TryStatement(TokenFactory.tokenFromKeyword(Keyword.T RY), body, catchClauses, finallyClause == null ? null : TokenFactory.tokenFromKe yword(Keyword.FINALLY), finallyClause);
408
409 static FunctionTypeAlias typeAlias(TypeName returnType, String name, TypeParam eterList typeParameters, FormalParameterList parameters) => new FunctionTypeAlia s(null, null, TokenFactory.tokenFromKeyword(Keyword.TYPEDEF), returnType, identi fier3(name), typeParameters, parameters, TokenFactory.tokenFromType(TokenType.SE MICOLON));
410
411 static TypeArgumentList typeArgumentList(List<TypeName> typeNames) => new Type ArgumentList(TokenFactory.tokenFromType(TokenType.LT), list(typeNames), TokenFac tory.tokenFromType(TokenType.GT));
412
413 /**
414 * Create a type name whose name has been resolved to the given element and wh ose type has been
415 * resolved to the type of the given element.
416 *
417 * <b>Note:</b> This method does not correctly handle class elements that have type parameters.
418 *
419 * @param element the element defining the type represented by the type name
420 * @return the type name that was created
421 */
422 static TypeName typeName(ClassElement element, List<TypeName> arguments) {
423 SimpleIdentifier name = identifier3(element.name);
424 name.staticElement = element;
425 TypeName typeName = typeName3(name, arguments);
426 typeName.type = element.type;
427 return typeName;
428 }
429
430 static TypeName typeName3(Identifier name, List<TypeName> arguments) {
431 if (arguments.length == 0) {
432 return new TypeName(name, null);
433 }
434 return new TypeName(name, typeArgumentList(arguments));
435 }
436
437 static TypeName typeName4(String name, List<TypeName> arguments) {
438 if (arguments.length == 0) {
439 return new TypeName(identifier3(name), null);
440 }
441 return new TypeName(identifier3(name), typeArgumentList(arguments));
442 }
443
444 static TypeParameter typeParameter(String name) => new TypeParameter(null, nul l, identifier3(name), null, null);
445
446 static TypeParameter typeParameter2(String name, TypeName bound) => new TypePa rameter(null, null, identifier3(name), TokenFactory.tokenFromKeyword(Keyword.EXT ENDS), bound);
447
448 static TypeParameterList typeParameterList(List<String> typeNames) {
449 List<TypeParameter> typeParameters = new List<TypeParameter>();
450 for (String typeName in typeNames) {
451 typeParameters.add(typeParameter(typeName));
452 }
453 return new TypeParameterList(TokenFactory.tokenFromType(TokenType.LT), typeP arameters, TokenFactory.tokenFromType(TokenType.GT));
454 }
455
456 static VariableDeclaration variableDeclaration(String name) => new VariableDec laration(null, null, identifier3(name), null, null);
457
458 static VariableDeclaration variableDeclaration2(String name, Expression initia lizer) => new VariableDeclaration(null, null, identifier3(name), TokenFactory.to kenFromType(TokenType.EQ), initializer);
459
460 static VariableDeclarationList variableDeclarationList(Keyword keyword, TypeNa me type, List<VariableDeclaration> variables) => new VariableDeclarationList(nul l, null, keyword == null ? null : TokenFactory.tokenFromKeyword(keyword), type, list(variables));
461
462 static VariableDeclarationList variableDeclarationList2(Keyword keyword, List< VariableDeclaration> variables) => variableDeclarationList(keyword, null, variab les);
463
464 static VariableDeclarationStatement variableDeclarationStatement(Keyword keywo rd, TypeName type, List<VariableDeclaration> variables) => new VariableDeclarati onStatement(variableDeclarationList(keyword, type, variables), TokenFactory.toke nFromType(TokenType.SEMICOLON));
465
466 static VariableDeclarationStatement variableDeclarationStatement2(Keyword keyw ord, List<VariableDeclaration> variables) => variableDeclarationStatement(keywor d, null, variables);
467
468 static WhileStatement whileStatement(Expression condition, Statement body) => new WhileStatement(TokenFactory.tokenFromKeyword(Keyword.WHILE), TokenFactory.to kenFromType(TokenType.OPEN_PAREN), condition, TokenFactory.tokenFromType(TokenTy pe.CLOSE_PAREN), body);
469
470 static WithClause withClause(List<TypeName> types) => new WithClause(TokenFact ory.tokenFromKeyword(Keyword.WITH), list(types));
471 }
472
473 class BreadthFirstVisitorTest extends ParserTestCase { 58 class BreadthFirstVisitorTest extends ParserTestCase {
474 void testIt() { 59 void testIt() {
475 String source = EngineTestCase.createSource([ 60 String source = EngineTestCase.createSource([
476 "class A {", 61 "class A {",
477 " bool get g => true;", 62 " bool get g => true;",
478 "}", 63 "}",
479 "class B {", 64 "class B {",
480 " int f() {", 65 " int f() {",
481 " num q() {", 66 " num q() {",
482 " return 3;", 67 " return 3;",
(...skipping 3783 matching lines...) Expand 10 before | Expand all | Expand 10 after
4266 ToSourceVisitorTest.dartSuite(); 3851 ToSourceVisitorTest.dartSuite();
4267 BreadthFirstVisitorTest.dartSuite(); 3852 BreadthFirstVisitorTest.dartSuite();
4268 ClassDeclarationTest.dartSuite(); 3853 ClassDeclarationTest.dartSuite();
4269 ClassTypeAliasTest.dartSuite(); 3854 ClassTypeAliasTest.dartSuite();
4270 IndexExpressionTest.dartSuite(); 3855 IndexExpressionTest.dartSuite();
4271 NodeListTest.dartSuite(); 3856 NodeListTest.dartSuite();
4272 SimpleIdentifierTest.dartSuite(); 3857 SimpleIdentifierTest.dartSuite();
4273 SimpleStringLiteralTest.dartSuite(); 3858 SimpleStringLiteralTest.dartSuite();
4274 VariableDeclarationTest.dartSuite(); 3859 VariableDeclarationTest.dartSuite();
4275 } 3860 }
OLDNEW
« no previous file with comments | « pkg/analyzer/pubspec.yaml ('k') | pkg/analyzer/test/generated/element_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698