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

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

Issue 259773005: New analyzer snapshot. Sorted unit members. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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'; 16 import 'package:analyzer/src/generated/utilities_dart.dart';
17 import 'package:analyzer/src/generated/element.dart' show ClassElement; 17 import 'package:analyzer/src/generated/element.dart' show ClassElement;
18 import 'package:unittest/unittest.dart' as _ut; 18 import 'package:unittest/unittest.dart' as _ut;
19 import 'parser_test.dart' show ParserTestCase; 19 import 'parser_test.dart' show ParserTestCase;
20 import 'test_support.dart'; 20 import 'test_support.dart';
21 import 'scanner_test.dart' show TokenFactory; 21 import 'scanner_test.dart' show TokenFactory;
22 22
23 class AssignmentKind extends Enum<AssignmentKind> {
24 static const AssignmentKind BINARY = const AssignmentKind('BINARY', 0);
25
26 static const AssignmentKind COMPOUND_LEFT = const AssignmentKind('COMPOUND_LEF T', 1);
27
28 static const AssignmentKind COMPOUND_RIGHT = const AssignmentKind('COMPOUND_RI GHT', 2);
29
30 static const AssignmentKind POSTFIX_INC = const AssignmentKind('POSTFIX_INC', 3);
31
32 static const AssignmentKind PREFIX_DEC = const AssignmentKind('PREFIX_DEC', 4) ;
33
34 static const AssignmentKind PREFIX_INC = const AssignmentKind('PREFIX_INC', 5) ;
35
36 static const AssignmentKind PREFIX_NOT = const AssignmentKind('PREFIX_NOT', 6) ;
37
38 static const AssignmentKind SIMPLE_LEFT = const AssignmentKind('SIMPLE_LEFT', 7);
39
40 static const AssignmentKind SIMPLE_RIGHT = const AssignmentKind('SIMPLE_RIGHT' , 8);
41
42 static const AssignmentKind NONE = const AssignmentKind('NONE', 9);
43
44 static const List<AssignmentKind> values = const [
45 BINARY,
46 COMPOUND_LEFT,
47 COMPOUND_RIGHT,
48 POSTFIX_INC,
49 PREFIX_DEC,
50 PREFIX_INC,
51 PREFIX_NOT,
52 SIMPLE_LEFT,
53 SIMPLE_RIGHT,
54 NONE];
55
56 const AssignmentKind(String name, int ordinal) : super(name, ordinal);
57 }
58
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 ArgumentDefinitionTest argumentDefinitionTest(String identifier) => new ArgumentDefinitionTest(TokenFactory.tokenFromType(TokenType.QUESTION), identifi er3(identifier));
79
80 static ArgumentList argumentList(List<Expression> arguments) => new ArgumentLi st(TokenFactory.tokenFromType(TokenType.OPEN_PAREN), list(arguments), TokenFacto ry.tokenFromType(TokenType.CLOSE_PAREN));
81
82 static AsExpression asExpression(Expression expression, TypeName type) => new AsExpression(expression, TokenFactory.tokenFromKeyword(Keyword.AS), type);
83
84 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));
85
86 static AssignmentExpression assignmentExpression(Expression leftHandSide, Toke nType operator, Expression rightHandSide) => new AssignmentExpression(leftHandSi de, TokenFactory.tokenFromType(operator), rightHandSide);
87
88 static BinaryExpression binaryExpression(Expression leftOperand, TokenType ope rator, Expression rightOperand) => new BinaryExpression(leftOperand, TokenFactor y.tokenFromType(operator), rightOperand);
89
90 static Block block(List<Statement> statements) => new Block(TokenFactory.token FromType(TokenType.OPEN_CURLY_BRACKET), list(statements), TokenFactory.tokenFrom Type(TokenType.CLOSE_CURLY_BRACKET));
91
92 static BlockFunctionBody blockFunctionBody(Block block) => new BlockFunctionBo dy(block);
93
94 static BlockFunctionBody blockFunctionBody2(List<Statement> statements) => new BlockFunctionBody(block(statements));
95
96 static BooleanLiteral booleanLiteral(bool value) => new BooleanLiteral(value ? TokenFactory.tokenFromKeyword(Keyword.TRUE) : TokenFactory.tokenFromKeyword(Key word.FALSE), value);
97
98 static BreakStatement breakStatement() => new BreakStatement(TokenFactory.toke nFromKeyword(Keyword.BREAK), null, TokenFactory.tokenFromType(TokenType.SEMICOLO N));
99
100 static BreakStatement breakStatement2(String label) => new BreakStatement(Toke nFactory.tokenFromKeyword(Keyword.BREAK), identifier3(label), TokenFactory.token FromType(TokenType.SEMICOLON));
101
102 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));
103
104 static MethodInvocation cascadedMethodInvocation(String methodName, List<Expre ssion> arguments) => new MethodInvocation(null, TokenFactory.tokenFromType(Token Type.PERIOD_PERIOD), identifier3(methodName), argumentList(arguments));
105
106 static PropertyAccess cascadedPropertyAccess(String propertyName) => new Prope rtyAccess(null, TokenFactory.tokenFromType(TokenType.PERIOD_PERIOD), identifier3 (propertyName));
107
108 static CascadeExpression cascadeExpression(Expression target, List<Expression> cascadeSections) => new CascadeExpression(target, list(cascadeSections));
109
110 static CatchClause catchClause(String exceptionParameter, List<Statement> stat ements) => catchClause5(null, exceptionParameter, null, statements);
111
112 static CatchClause catchClause2(String exceptionParameter, String stackTracePa rameter, List<Statement> statements) => catchClause5(null, exceptionParameter, s tackTraceParameter, statements);
113
114 static CatchClause catchClause3(TypeName exceptionType, List<Statement> statem ents) => catchClause5(exceptionType, null, null, statements);
115
116 static CatchClause catchClause4(TypeName exceptionType, String exceptionParame ter, List<Statement> statements) => catchClause5(exceptionType, exceptionParamet er, null, statements);
117
118 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));
119
120 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));
121
122 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));
123
124 static CompilationUnit compilationUnit() => compilationUnit8(null, null, null) ;
125
126 static CompilationUnit compilationUnit2(List<CompilationUnitMember> declaratio ns) => compilationUnit8(null, null, list(declarations));
127
128 static CompilationUnit compilationUnit3(List<Directive> directives) => compila tionUnit8(null, list(directives), null);
129
130 static CompilationUnit compilationUnit4(List<Directive> directives, List<Compi lationUnitMember> declarations) => compilationUnit8(null, directives, declaratio ns);
131
132 static CompilationUnit compilationUnit5(String scriptTag) => compilationUnit8( scriptTag, null, null);
133
134 static CompilationUnit compilationUnit6(String scriptTag, List<CompilationUnit Member> declarations) => compilationUnit8(scriptTag, null, list(declarations));
135
136 static CompilationUnit compilationUnit7(String scriptTag, List<Directive> dire ctives) => compilationUnit8(scriptTag, list(directives), null);
137
138 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));
139
140 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);
141
142 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());
143
144 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);
145
146 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);
147
148 static ConstructorName constructorName(TypeName type, String name) => new Cons tructorName(type, name == null ? null : TokenFactory.tokenFromType(TokenType.PER IOD), name == null ? null : identifier3(name));
149
150 static ContinueStatement continueStatement([String label]) {
151 SimpleIdentifier labelNode = label == null ? null : identifier3(label);
152 return new ContinueStatement(TokenFactory.tokenFromKeyword(Keyword.CONTINUE) , labelNode, TokenFactory.tokenFromType(TokenType.SEMICOLON));
153 }
154
155 static DeclaredIdentifier declaredIdentifier(Keyword keyword, String identifie r) => declaredIdentifier2(keyword, null, identifier);
156
157 static DeclaredIdentifier declaredIdentifier2(Keyword keyword, TypeName type, String identifier) => new DeclaredIdentifier(null, null, keyword == null ? null : TokenFactory.tokenFromKeyword(keyword), type, identifier3(identifier));
158
159 static DeclaredIdentifier declaredIdentifier3(String identifier) => declaredId entifier2(null, null, identifier);
160
161 static DeclaredIdentifier declaredIdentifier4(TypeName type, String identifier ) => declaredIdentifier2(null, type, identifier);
162
163 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));
164
165 static DoubleLiteral doubleLiteral(double value) => new DoubleLiteral(TokenFac tory.tokenFromString(value.toString()), value);
166
167 static EmptyFunctionBody emptyFunctionBody() => new EmptyFunctionBody(TokenFac tory.tokenFromType(TokenType.SEMICOLON));
168
169 static EmptyStatement emptyStatement() => new EmptyStatement(TokenFactory.toke nFromType(TokenType.SEMICOLON));
170
171 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));
172
173 static ExportDirective exportDirective2(String uri, List<Combinator> combinato rs) => exportDirective(new List<Annotation>(), uri, combinators);
174
175 static ExpressionFunctionBody expressionFunctionBody(Expression expression) => new ExpressionFunctionBody(TokenFactory.tokenFromType(TokenType.FUNCTION), expr ession, TokenFactory.tokenFromType(TokenType.SEMICOLON));
176
177 static ExpressionStatement expressionStatement(Expression expression) => new E xpressionStatement(expression, TokenFactory.tokenFromType(TokenType.SEMICOLON));
178
179 static ExtendsClause extendsClause(TypeName type) => new ExtendsClause(TokenFa ctory.tokenFromKeyword(Keyword.EXTENDS), type);
180
181 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));
182
183 static FieldDeclaration fieldDeclaration2(bool isStatic, Keyword keyword, List <VariableDeclaration> variables) => fieldDeclaration(isStatic, keyword, null, va riables);
184
185 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);
186
187 static FieldFormalParameter fieldFormalParameter2(String identifier) => fieldF ormalParameter(null, null, identifier);
188
189 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);
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, String prefix, List<Combinator> combinators) => new ImportDirective(null, metada ta, TokenFactory.tokenFromKeyword(Keyword.IMPORT), string2(uri), null, prefix == null ? null : TokenFactory.tokenFromKeyword(Keyword.AS), prefix == null ? null : identifier3(prefix), list(combinators), TokenFactory.tokenFromType(TokenType.S EMICOLON));
234
235 static ImportDirective importDirective2(String uri, String prefix, List<Combin ator> combinators) => importDirective(new List<Annotation>(), uri, prefix, combi nators);
236
237 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 ));
238
239 static InstanceCreationExpression instanceCreationExpression(Keyword keyword, ConstructorName name, List<Expression> arguments) => new InstanceCreationExpress ion(keyword == null ? null : TokenFactory.tokenFromKeyword(keyword), name, argum entList(arguments));
240
241 static InstanceCreationExpression instanceCreationExpression2(Keyword keyword, TypeName type, List<Expression> arguments) => instanceCreationExpression3(keywo rd, type, null, arguments);
242
243 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);
244
245 static IntegerLiteral integer(int value) => new IntegerLiteral(TokenFactory.to kenFromTypeAndString(TokenType.INT, value.toString()), value);
246
247 static InterpolationExpression interpolationExpression(Expression expression) => new InterpolationExpression(TokenFactory.tokenFromType(TokenType.STRING_INTER POLATION_EXPRESSION), expression, TokenFactory.tokenFromType(TokenType.CLOSE_CUR LY_BRACKET));
248
249 static InterpolationExpression interpolationExpression2(String identifier) => new InterpolationExpression(TokenFactory.tokenFromType(TokenType.STRING_INTERPOL ATION_IDENTIFIER), identifier3(identifier), null);
250
251 static InterpolationString interpolationString(String contents, String value) => new InterpolationString(TokenFactory.tokenFromString(contents), value);
252
253 static IsExpression isExpression(Expression expression, bool negated, TypeName type) => new IsExpression(expression, TokenFactory.tokenFromKeyword(Keyword.IS) , negated ? TokenFactory.tokenFromType(TokenType.BANG) : null, type);
254
255 static Label label(SimpleIdentifier label) => new Label(label, TokenFactory.to kenFromType(TokenType.COLON));
256
257 static Label label2(String label) => AstFactory.label(identifier3(label));
258
259 static LabeledStatement labeledStatement(List<Label> labels, Statement stateme nt) => new LabeledStatement(labels, statement);
260
261 static LibraryDirective libraryDirective(List<Annotation> metadata, LibraryIde ntifier libraryName) => new LibraryDirective(null, metadata, TokenFactory.tokenF romKeyword(Keyword.LIBRARY), libraryName, TokenFactory.tokenFromType(TokenType.S EMICOLON));
262
263 static LibraryDirective libraryDirective2(String libraryName) => libraryDirect ive(new List<Annotation>(), libraryIdentifier2([libraryName]));
264
265 static LibraryIdentifier libraryIdentifier(List<SimpleIdentifier> components) => new LibraryIdentifier(list(components));
266
267 static LibraryIdentifier libraryIdentifier2(List<String> components) {
268 List<SimpleIdentifier> componentList = new List<SimpleIdentifier>();
269 for (String component in components) {
270 componentList.add(identifier3(component));
271 }
272 return new LibraryIdentifier(componentList);
273 }
274
275 static List list(List<Object> elements) {
276 List elementList = new List();
277 for (Object element in elements) {
278 elementList.add(element);
279 }
280 return elementList;
281 }
282
283 static ListLiteral listLiteral(List<Expression> elements) => listLiteral2(null , null, elements);
284
285 static ListLiteral listLiteral2(Keyword keyword, TypeArgumentList typeArgument s, List<Expression> elements) => new ListLiteral(keyword == null ? null : TokenF actory.tokenFromKeyword(keyword), null, TokenFactory.tokenFromType(TokenType.OPE N_SQUARE_BRACKET), list(elements), TokenFactory.tokenFromType(TokenType.CLOSE_SQ UARE_BRACKET));
286
287 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));
288
289 static MapLiteral mapLiteral2(List<MapLiteralEntry> entries) => mapLiteral(nul l, null, entries);
290
291 static MapLiteralEntry mapLiteralEntry(String key, Expression value) => new Ma pLiteralEntry(string2(key), TokenFactory.tokenFromType(TokenType.COLON), value);
292
293 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());
294
295 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);
296
297 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));
298
299 static MethodInvocation methodInvocation2(String methodName, List<Expression> arguments) => methodInvocation(null, methodName, arguments);
300
301 static NamedExpression namedExpression(Label label, Expression expression) => new NamedExpression(label, expression);
302
303 static NamedExpression namedExpression2(String label, Expression expression) = > namedExpression(label2(label), expression);
304
305 static DefaultFormalParameter namedFormalParameter(NormalFormalParameter param eter, Expression expression) => new DefaultFormalParameter(parameter, ParameterK ind.NAMED, expression == null ? null : TokenFactory.tokenFromType(TokenType.COLO N), expression);
306
307 static NativeClause nativeClause(String nativeCode) => new NativeClause(TokenF actory.tokenFromString("native"), string2(nativeCode));
308
309 static NativeFunctionBody nativeFunctionBody(String nativeMethodName) => new N ativeFunctionBody(TokenFactory.tokenFromString("native"), string2(nativeMethodNa me), TokenFactory.tokenFromType(TokenType.SEMICOLON));
310
311 static NullLiteral nullLiteral() => new NullLiteral(TokenFactory.tokenFromKeyw ord(Keyword.NULL));
312
313 static ParenthesizedExpression parenthesizedExpression(Expression expression) => new ParenthesizedExpression(TokenFactory.tokenFromType(TokenType.OPEN_PAREN), expression, TokenFactory.tokenFromType(TokenType.CLOSE_PAREN));
314
315 static PartDirective partDirective(List<Annotation> metadata, String url) => n ew PartDirective(null, metadata, TokenFactory.tokenFromKeyword(Keyword.PART), st ring2(url), TokenFactory.tokenFromType(TokenType.SEMICOLON));
316
317 static PartDirective partDirective2(String url) => partDirective(new List<Anno tation>(), url);
318
319 static PartOfDirective partOfDirective(LibraryIdentifier libraryName) => partO fDirective2(new List<Annotation>(), libraryName);
320
321 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));
322
323 static DefaultFormalParameter positionalFormalParameter(NormalFormalParameter parameter, Expression expression) => new DefaultFormalParameter(parameter, Param eterKind.POSITIONAL, expression == null ? null : TokenFactory.tokenFromType(Toke nType.EQ), expression);
324
325 static PostfixExpression postfixExpression(Expression expression, TokenType op erator) => new PostfixExpression(expression, TokenFactory.tokenFromType(operator ));
326
327 static PrefixExpression prefixExpression(TokenType operator, Expression expres sion) => new PrefixExpression(TokenFactory.tokenFromType(operator), expression);
328
329 static PropertyAccess propertyAccess(Expression target, SimpleIdentifier prope rtyName) => new PropertyAccess(target, TokenFactory.tokenFromType(TokenType.PERI OD), propertyName);
330
331 static PropertyAccess propertyAccess2(Expression target, String propertyName) => new PropertyAccess(target, TokenFactory.tokenFromType(TokenType.PERIOD), iden tifier3(propertyName));
332
333 static RedirectingConstructorInvocation redirectingConstructorInvocation(List< Expression> arguments) => redirectingConstructorInvocation2(null, arguments);
334
335 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));
336
337 static RethrowExpression rethrowExpression() => new RethrowExpression(TokenFac tory.tokenFromKeyword(Keyword.RETHROW));
338
339 static ReturnStatement returnStatement() => returnStatement2(null);
340
341 static ReturnStatement returnStatement2(Expression expression) => new ReturnSt atement(TokenFactory.tokenFromKeyword(Keyword.RETURN), expression, TokenFactory. tokenFromType(TokenType.SEMICOLON));
342
343 static ScriptTag scriptTag(String scriptTag) => new ScriptTag(TokenFactory.tok enFromString(scriptTag));
344
345 static ShowCombinator showCombinator(List<SimpleIdentifier> identifiers) => ne w ShowCombinator(TokenFactory.tokenFromString("show"), list(identifiers));
346
347 static ShowCombinator showCombinator2(List<String> identifiers) {
348 List<SimpleIdentifier> identifierList = new List<SimpleIdentifier>();
349 for (String identifier in identifiers) {
350 identifierList.add(identifier3(identifier));
351 }
352 return new ShowCombinator(TokenFactory.tokenFromString("show"), identifierLi st);
353 }
354
355 static SimpleFormalParameter simpleFormalParameter(Keyword keyword, String par ameterName) => simpleFormalParameter2(keyword, null, parameterName);
356
357 static SimpleFormalParameter simpleFormalParameter2(Keyword keyword, TypeName type, String parameterName) => new SimpleFormalParameter(null, null, keyword == null ? null : TokenFactory.tokenFromKeyword(keyword), type, identifier3(paramete rName));
358
359 static SimpleFormalParameter simpleFormalParameter3(String parameterName) => s impleFormalParameter2(null, null, parameterName);
360
361 static SimpleFormalParameter simpleFormalParameter4(TypeName type, String para meterName) => simpleFormalParameter2(null, type, parameterName);
362
363 static StringInterpolation string(List<InterpolationElement> elements) => new StringInterpolation(list(elements));
364
365 static SimpleStringLiteral string2(String content) => new SimpleStringLiteral( TokenFactory.tokenFromString("'${content}'"), content);
366
367 static SuperConstructorInvocation superConstructorInvocation(List<Expression> arguments) => superConstructorInvocation2(null, arguments);
368
369 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));
370
371 static SuperExpression superExpression() => new SuperExpression(TokenFactory.t okenFromKeyword(Keyword.SUPER));
372
373 static SwitchCase switchCase(Expression expression, List<Statement> statements ) => switchCase2(new List<Label>(), expression, statements);
374
375 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));
376
377 static SwitchDefault switchDefault(List<Label> labels, List<Statement> stateme nts) => new SwitchDefault(labels, TokenFactory.tokenFromKeyword(Keyword.DEFAULT) , TokenFactory.tokenFromType(TokenType.COLON), list(statements));
378
379 static SwitchDefault switchDefault2(List<Statement> statements) => switchDefau lt(new List<Label>(), statements);
380
381 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));
382
383 static SymbolLiteral symbolLiteral(List<String> components) {
384 List<Token> identifierList = new List<Token>();
385 for (String component in components) {
386 identifierList.add(TokenFactory.tokenFromTypeAndString(TokenType.IDENTIFIE R, component));
387 }
388 return new SymbolLiteral(TokenFactory.tokenFromType(TokenType.HASH), new Lis t.from(identifierList));
389 }
390
391 static ThisExpression thisExpression() => new ThisExpression(TokenFactory.toke nFromKeyword(Keyword.THIS));
392
393 static ThrowExpression throwExpression() => throwExpression2(null);
394
395 static ThrowExpression throwExpression2(Expression expression) => new ThrowExp ression(TokenFactory.tokenFromKeyword(Keyword.THROW), expression);
396
397 static TopLevelVariableDeclaration topLevelVariableDeclaration(Keyword keyword , TypeName type, List<VariableDeclaration> variables) => new TopLevelVariableDec laration(null, null, variableDeclarationList(keyword, type, variables), TokenFac tory.tokenFromType(TokenType.SEMICOLON));
398
399 static TopLevelVariableDeclaration topLevelVariableDeclaration2(Keyword keywor d, List<VariableDeclaration> variables) => new TopLevelVariableDeclaration(null, null, variableDeclarationList(keyword, null, variables), TokenFactory.tokenFrom Type(TokenType.SEMICOLON));
400
401 static TryStatement tryStatement(Block body, Block finallyClause) => tryStatem ent3(body, new List<CatchClause>(), finallyClause);
402
403 static TryStatement tryStatement2(Block body, List<CatchClause> catchClauses) => tryStatement3(body, list(catchClauses), null);
404
405 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);
406
407 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));
408
409 static TypeArgumentList typeArgumentList(List<TypeName> typeNames) => new Type ArgumentList(TokenFactory.tokenFromType(TokenType.LT), list(typeNames), TokenFac tory.tokenFromType(TokenType.GT));
410
411 /**
412 * Create a type name whose name has been resolved to the given element and wh ose type has been
413 * resolved to the type of the given element.
414 *
415 * <b>Note:</b> This method does not correctly handle class elements that have type parameters.
416 *
417 * @param element the element defining the type represented by the type name
418 * @return the type name that was created
419 */
420 static TypeName typeName(ClassElement element, List<TypeName> arguments) {
421 SimpleIdentifier name = identifier3(element.name);
422 name.staticElement = element;
423 TypeName typeName = typeName3(name, arguments);
424 typeName.type = element.type;
425 return typeName;
426 }
427
428 static TypeName typeName3(Identifier name, List<TypeName> arguments) {
429 if (arguments.length == 0) {
430 return new TypeName(name, null);
431 }
432 return new TypeName(name, typeArgumentList(arguments));
433 }
434
435 static TypeName typeName4(String name, List<TypeName> arguments) {
436 if (arguments.length == 0) {
437 return new TypeName(identifier3(name), null);
438 }
439 return new TypeName(identifier3(name), typeArgumentList(arguments));
440 }
441
442 static TypeParameter typeParameter(String name) => new TypeParameter(null, nul l, identifier3(name), null, null);
443
444 static TypeParameter typeParameter2(String name, TypeName bound) => new TypePa rameter(null, null, identifier3(name), TokenFactory.tokenFromKeyword(Keyword.EXT ENDS), bound);
445
446 static TypeParameterList typeParameterList(List<String> typeNames) {
447 List<TypeParameter> typeParameters = new List<TypeParameter>();
448 for (String typeName in typeNames) {
449 typeParameters.add(typeParameter(typeName));
450 }
451 return new TypeParameterList(TokenFactory.tokenFromType(TokenType.LT), typeP arameters, TokenFactory.tokenFromType(TokenType.GT));
452 }
453
454 static VariableDeclaration variableDeclaration(String name) => new VariableDec laration(null, null, identifier3(name), null, null);
455
456 static VariableDeclaration variableDeclaration2(String name, Expression initia lizer) => new VariableDeclaration(null, null, identifier3(name), TokenFactory.to kenFromType(TokenType.EQ), initializer);
457
458 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));
459
460 static VariableDeclarationList variableDeclarationList2(Keyword keyword, List< VariableDeclaration> variables) => variableDeclarationList(keyword, null, variab les);
461
462 static VariableDeclarationStatement variableDeclarationStatement(Keyword keywo rd, TypeName type, List<VariableDeclaration> variables) => new VariableDeclarati onStatement(variableDeclarationList(keyword, type, variables), TokenFactory.toke nFromType(TokenType.SEMICOLON));
463
464 static VariableDeclarationStatement variableDeclarationStatement2(Keyword keyw ord, List<VariableDeclaration> variables) => variableDeclarationStatement(keywor d, null, variables);
465
466 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);
467
468 static WithClause withClause(List<TypeName> types) => new WithClause(TokenFact ory.tokenFromKeyword(Keyword.WITH), list(types));
469 }
470
471 class BreadthFirstVisitorTest extends ParserTestCase {
472 void testIt() {
473 String source = EngineTestCase.createSource([
474 "class A {",
475 " bool get g => true;",
476 "}",
477 "class B {",
478 " int f() {",
479 " num q() {",
480 " return 3;",
481 " }",
482 " return q() + 4;",
483 " }",
484 "}",
485 "A f(var p) {",
486 " if ((p as A).g) {",
487 " return p;",
488 " } else {",
489 " return null;",
490 " }",
491 "}"]);
492 CompilationUnit unit = ParserTestCase.parseCompilationUnit(source, []);
493 List<AstNode> nodes = new List<AstNode>();
494 BreadthFirstVisitor<Object> visitor = new BreadthFirstVisitor_BreadthFirstVi sitorTest_testIt(nodes);
495 visitor.visitAllNodes(unit);
496 EngineTestCase.assertSizeOfList(59, nodes);
497 EngineTestCase.assertInstanceOf((obj) => obj is CompilationUnit, Compilation Unit, nodes[0]);
498 EngineTestCase.assertInstanceOf((obj) => obj is ClassDeclaration, ClassDecla ration, nodes[2]);
499 EngineTestCase.assertInstanceOf((obj) => obj is FunctionDeclaration, Functio nDeclaration, nodes[3]);
500 EngineTestCase.assertInstanceOf((obj) => obj is FunctionDeclarationStatement , FunctionDeclarationStatement, nodes[27]);
501 EngineTestCase.assertInstanceOf((obj) => obj is IntegerLiteral, IntegerLiter al, nodes[58]);
502 }
503
504 static dartSuite() {
505 _ut.group('BreadthFirstVisitorTest', () {
506 _ut.test('testIt', () {
507 final __test = new BreadthFirstVisitorTest();
508 runJUnitTest(__test, __test.testIt);
509 });
510 });
511 }
512 }
513
514 class BreadthFirstVisitor_BreadthFirstVisitorTest_testIt extends BreadthFirstVis itor<Object> {
515 List<AstNode> nodes;
516
517 BreadthFirstVisitor_BreadthFirstVisitorTest_testIt(this.nodes) : super();
518
519 @override
520 Object visitNode(AstNode node) {
521 nodes.add(node);
522 return super.visitNode(node);
523 }
524 }
525
526 class ClassDeclarationTest extends ParserTestCase {
527 void test_getConstructor() {
528 List<ConstructorInitializer> initializers = new List<ConstructorInitializer> ();
529 ConstructorDeclaration defaultConstructor = AstFactory.constructorDeclaratio n(AstFactory.identifier3("Test"), null, AstFactory.formalParameterList([]), init ializers);
530 ConstructorDeclaration aConstructor = AstFactory.constructorDeclaration(AstF actory.identifier3("Test"), "a", AstFactory.formalParameterList([]), initializer s);
531 ConstructorDeclaration bConstructor = AstFactory.constructorDeclaration(AstF actory.identifier3("Test"), "b", AstFactory.formalParameterList([]), initializer s);
532 ClassDeclaration clazz = AstFactory.classDeclaration(null, "Test", null, nul l, null, null, [defaultConstructor, aConstructor, bConstructor]);
533 JUnitTestCase.assertSame(defaultConstructor, clazz.getConstructor(null));
534 JUnitTestCase.assertSame(aConstructor, clazz.getConstructor("a"));
535 JUnitTestCase.assertSame(bConstructor, clazz.getConstructor("b"));
536 JUnitTestCase.assertSame(null, clazz.getConstructor("noSuchConstructor"));
537 }
538
539 void test_getField() {
540 VariableDeclaration aVar = AstFactory.variableDeclaration("a");
541 VariableDeclaration bVar = AstFactory.variableDeclaration("b");
542 VariableDeclaration cVar = AstFactory.variableDeclaration("c");
543 ClassDeclaration clazz = AstFactory.classDeclaration(null, "Test", null, nul l, null, null, [
544 AstFactory.fieldDeclaration2(false, null, [aVar]),
545 AstFactory.fieldDeclaration2(false, null, [bVar, cVar])]);
546 JUnitTestCase.assertSame(aVar, clazz.getField("a"));
547 JUnitTestCase.assertSame(bVar, clazz.getField("b"));
548 JUnitTestCase.assertSame(cVar, clazz.getField("c"));
549 JUnitTestCase.assertSame(null, clazz.getField("noSuchField"));
550 }
551
552 void test_getMethod() {
553 MethodDeclaration aMethod = AstFactory.methodDeclaration(null, null, null, n ull, AstFactory.identifier3("a"), AstFactory.formalParameterList([]));
554 MethodDeclaration bMethod = AstFactory.methodDeclaration(null, null, null, n ull, AstFactory.identifier3("b"), AstFactory.formalParameterList([]));
555 ClassDeclaration clazz = AstFactory.classDeclaration(null, "Test", null, nul l, null, null, [aMethod, bMethod]);
556 JUnitTestCase.assertSame(aMethod, clazz.getMethod("a"));
557 JUnitTestCase.assertSame(bMethod, clazz.getMethod("b"));
558 JUnitTestCase.assertSame(null, clazz.getMethod("noSuchMethod"));
559 }
560
561 void test_isAbstract() {
562 JUnitTestCase.assertFalse(AstFactory.classDeclaration(null, "A", null, null, null, null, []).isAbstract);
563 JUnitTestCase.assertTrue(AstFactory.classDeclaration(Keyword.ABSTRACT, "B", null, null, null, null, []).isAbstract);
564 }
565
566 static dartSuite() {
567 _ut.group('ClassDeclarationTest', () {
568 _ut.test('test_getConstructor', () {
569 final __test = new ClassDeclarationTest();
570 runJUnitTest(__test, __test.test_getConstructor);
571 });
572 _ut.test('test_getField', () {
573 final __test = new ClassDeclarationTest();
574 runJUnitTest(__test, __test.test_getField);
575 });
576 _ut.test('test_getMethod', () {
577 final __test = new ClassDeclarationTest();
578 runJUnitTest(__test, __test.test_getMethod);
579 });
580 _ut.test('test_isAbstract', () {
581 final __test = new ClassDeclarationTest();
582 runJUnitTest(__test, __test.test_isAbstract);
583 });
584 });
585 }
586 }
587
588 class ClassTypeAliasTest extends ParserTestCase {
589 void test_isAbstract() {
590 JUnitTestCase.assertFalse(AstFactory.classTypeAlias("A", null, null, null, n ull, null).isAbstract);
591 JUnitTestCase.assertTrue(AstFactory.classTypeAlias("B", null, Keyword.ABSTRA CT, null, null, null).isAbstract);
592 }
593
594 static dartSuite() {
595 _ut.group('ClassTypeAliasTest', () {
596 _ut.test('test_isAbstract', () {
597 final __test = new ClassTypeAliasTest();
598 runJUnitTest(__test, __test.test_isAbstract);
599 });
600 });
601 }
602 }
603
604 class ConstantEvaluatorTest extends ParserTestCase {
605 void fail_constructor() {
606 Object value = _getConstantValue("?");
607 JUnitTestCase.assertEquals(null, value);
608 }
609
610 void fail_identifier_class() {
611 Object value = _getConstantValue("?");
612 JUnitTestCase.assertEquals(null, value);
613 }
614
615 void fail_identifier_function() {
616 Object value = _getConstantValue("?");
617 JUnitTestCase.assertEquals(null, value);
618 }
619
620 void fail_identifier_static() {
621 Object value = _getConstantValue("?");
622 JUnitTestCase.assertEquals(null, value);
623 }
624
625 void fail_identifier_staticMethod() {
626 Object value = _getConstantValue("?");
627 JUnitTestCase.assertEquals(null, value);
628 }
629
630 void fail_identifier_topLevel() {
631 Object value = _getConstantValue("?");
632 JUnitTestCase.assertEquals(null, value);
633 }
634
635 void fail_identifier_typeParameter() {
636 Object value = _getConstantValue("?");
637 JUnitTestCase.assertEquals(null, value);
638 }
639
640 void test_binary_bitAnd() {
641 Object value = _getConstantValue("74 & 42");
642 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
643 JUnitTestCase.assertEquals(74 & 42, value as int);
644 }
645
646 void test_binary_bitOr() {
647 Object value = _getConstantValue("74 | 42");
648 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
649 JUnitTestCase.assertEquals(74 | 42, value as int);
650 }
651
652 void test_binary_bitXor() {
653 Object value = _getConstantValue("74 ^ 42");
654 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
655 JUnitTestCase.assertEquals(74 ^ 42, value as int);
656 }
657
658 void test_binary_divide_double() {
659 Object value = _getConstantValue("3.2 / 2.3");
660 EngineTestCase.assertInstanceOf((obj) => obj is double, double, value);
661 JUnitTestCase.assertEquals(3.2 / 2.3, value as double);
662 }
663
664 void test_binary_divide_integer() {
665 Object value = _getConstantValue("3 / 2");
666 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
667 JUnitTestCase.assertEquals(1, value as int);
668 }
669
670 void test_binary_equal_boolean() {
671 Object value = _getConstantValue("true == false");
672 JUnitTestCase.assertEquals(false, value);
673 }
674
675 void test_binary_equal_integer() {
676 Object value = _getConstantValue("2 == 3");
677 JUnitTestCase.assertEquals(false, value);
678 }
679
680 void test_binary_equal_invalidLeft() {
681 Object value = _getConstantValue("a == 3");
682 JUnitTestCase.assertEquals(ConstantEvaluator.NOT_A_CONSTANT, value);
683 }
684
685 void test_binary_equal_invalidRight() {
686 Object value = _getConstantValue("2 == a");
687 JUnitTestCase.assertEquals(ConstantEvaluator.NOT_A_CONSTANT, value);
688 }
689
690 void test_binary_equal_string() {
691 Object value = _getConstantValue("'a' == 'b'");
692 JUnitTestCase.assertEquals(false, value);
693 }
694
695 void test_binary_greaterThan() {
696 Object value = _getConstantValue("2 > 3");
697 JUnitTestCase.assertEquals(false, value);
698 }
699
700 void test_binary_greaterThanOrEqual() {
701 Object value = _getConstantValue("2 >= 3");
702 JUnitTestCase.assertEquals(false, value);
703 }
704
705 void test_binary_leftShift() {
706 Object value = _getConstantValue("16 << 2");
707 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
708 JUnitTestCase.assertEquals(64, value as int);
709 }
710
711 void test_binary_lessThan() {
712 Object value = _getConstantValue("2 < 3");
713 JUnitTestCase.assertEquals(true, value);
714 }
715
716 void test_binary_lessThanOrEqual() {
717 Object value = _getConstantValue("2 <= 3");
718 JUnitTestCase.assertEquals(true, value);
719 }
720
721 void test_binary_logicalAnd() {
722 Object value = _getConstantValue("true && false");
723 JUnitTestCase.assertEquals(false, value);
724 }
725
726 void test_binary_logicalOr() {
727 Object value = _getConstantValue("true || false");
728 JUnitTestCase.assertEquals(true, value);
729 }
730
731 void test_binary_minus_double() {
732 Object value = _getConstantValue("3.2 - 2.3");
733 EngineTestCase.assertInstanceOf((obj) => obj is double, double, value);
734 JUnitTestCase.assertEquals(3.2 - 2.3, value as double);
735 }
736
737 void test_binary_minus_integer() {
738 Object value = _getConstantValue("3 - 2");
739 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
740 JUnitTestCase.assertEquals(1, value as int);
741 }
742
743 void test_binary_notEqual_boolean() {
744 Object value = _getConstantValue("true != false");
745 JUnitTestCase.assertEquals(true, value);
746 }
747
748 void test_binary_notEqual_integer() {
749 Object value = _getConstantValue("2 != 3");
750 JUnitTestCase.assertEquals(true, value);
751 }
752
753 void test_binary_notEqual_invalidLeft() {
754 Object value = _getConstantValue("a != 3");
755 JUnitTestCase.assertEquals(ConstantEvaluator.NOT_A_CONSTANT, value);
756 }
757
758 void test_binary_notEqual_invalidRight() {
759 Object value = _getConstantValue("2 != a");
760 JUnitTestCase.assertEquals(ConstantEvaluator.NOT_A_CONSTANT, value);
761 }
762
763 void test_binary_notEqual_string() {
764 Object value = _getConstantValue("'a' != 'b'");
765 JUnitTestCase.assertEquals(true, value);
766 }
767
768 void test_binary_plus_double() {
769 Object value = _getConstantValue("2.3 + 3.2");
770 EngineTestCase.assertInstanceOf((obj) => obj is double, double, value);
771 JUnitTestCase.assertEquals(2.3 + 3.2, value as double);
772 }
773
774 void test_binary_plus_integer() {
775 Object value = _getConstantValue("2 + 3");
776 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
777 JUnitTestCase.assertEquals(5, value as int);
778 }
779
780 void test_binary_remainder_double() {
781 Object value = _getConstantValue("3.2 % 2.3");
782 EngineTestCase.assertInstanceOf((obj) => obj is double, double, value);
783 JUnitTestCase.assertEquals(3.2 % 2.3, value as double);
784 }
785
786 void test_binary_remainder_integer() {
787 Object value = _getConstantValue("8 % 3");
788 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
789 JUnitTestCase.assertEquals(2, value as int);
790 }
791
792 void test_binary_rightShift() {
793 Object value = _getConstantValue("64 >> 2");
794 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
795 JUnitTestCase.assertEquals(16, value as int);
796 }
797
798 void test_binary_times_double() {
799 Object value = _getConstantValue("2.3 * 3.2");
800 EngineTestCase.assertInstanceOf((obj) => obj is double, double, value);
801 JUnitTestCase.assertEquals(2.3 * 3.2, value as double);
802 }
803
804 void test_binary_times_integer() {
805 Object value = _getConstantValue("2 * 3");
806 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
807 JUnitTestCase.assertEquals(6, value as int);
808 }
809
810 void test_binary_truncatingDivide_double() {
811 Object value = _getConstantValue("3.2 ~/ 2.3");
812 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
813 JUnitTestCase.assertEquals(1, value as int);
814 }
815
816 void test_binary_truncatingDivide_integer() {
817 Object value = _getConstantValue("10 ~/ 3");
818 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
819 JUnitTestCase.assertEquals(3, value as int);
820 }
821
822 void test_literal_boolean_false() {
823 Object value = _getConstantValue("false");
824 JUnitTestCase.assertEquals(false, value);
825 }
826
827 void test_literal_boolean_true() {
828 Object value = _getConstantValue("true");
829 JUnitTestCase.assertEquals(true, value);
830 }
831
832 void test_literal_list() {
833 Object value = _getConstantValue("['a', 'b', 'c']");
834 EngineTestCase.assertInstanceOf((obj) => obj is List, List, value);
835 List list = value as List;
836 JUnitTestCase.assertEquals(3, list.length);
837 JUnitTestCase.assertEquals("a", list[0]);
838 JUnitTestCase.assertEquals("b", list[1]);
839 JUnitTestCase.assertEquals("c", list[2]);
840 }
841
842 void test_literal_map() {
843 Object value = _getConstantValue("{'a' : 'm', 'b' : 'n', 'c' : 'o'}");
844 EngineTestCase.assertInstanceOf((obj) => obj is Map, Map, value);
845 Map map = value as Map;
846 JUnitTestCase.assertEquals(3, map.length);
847 JUnitTestCase.assertEquals("m", map["a"]);
848 JUnitTestCase.assertEquals("n", map["b"]);
849 JUnitTestCase.assertEquals("o", map["c"]);
850 }
851
852 void test_literal_null() {
853 Object value = _getConstantValue("null");
854 JUnitTestCase.assertEquals(null, value);
855 }
856
857 void test_literal_number_double() {
858 Object value = _getConstantValue("3.45");
859 EngineTestCase.assertInstanceOf((obj) => obj is double, double, value);
860 JUnitTestCase.assertEquals(3.45, value as double);
861 }
862
863 void test_literal_number_integer() {
864 Object value = _getConstantValue("42");
865 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
866 JUnitTestCase.assertEquals(42, value as int);
867 }
868
869 void test_literal_string_adjacent() {
870 Object value = _getConstantValue("'abc' 'def'");
871 JUnitTestCase.assertEquals("abcdef", value);
872 }
873
874 void test_literal_string_interpolation_invalid() {
875 Object value = _getConstantValue("'a\${f()}c'");
876 JUnitTestCase.assertEquals(ConstantEvaluator.NOT_A_CONSTANT, value);
877 }
878
879 void test_literal_string_interpolation_valid() {
880 Object value = _getConstantValue("'a\${3}c'");
881 JUnitTestCase.assertEquals("a3c", value);
882 }
883
884 void test_literal_string_simple() {
885 Object value = _getConstantValue("'abc'");
886 JUnitTestCase.assertEquals("abc", value);
887 }
888
889 void test_parenthesizedExpression() {
890 Object value = _getConstantValue("('a')");
891 JUnitTestCase.assertEquals("a", value);
892 }
893
894 void test_unary_bitNot() {
895 Object value = _getConstantValue("~42");
896 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
897 JUnitTestCase.assertEquals(~42, value as int);
898 }
899
900 void test_unary_logicalNot() {
901 Object value = _getConstantValue("!true");
902 JUnitTestCase.assertEquals(false, value);
903 }
904
905 void test_unary_negated_double() {
906 Object value = _getConstantValue("-42.3");
907 EngineTestCase.assertInstanceOf((obj) => obj is double, double, value);
908 JUnitTestCase.assertEquals(-42.3, value as double);
909 }
910
911 void test_unary_negated_integer() {
912 Object value = _getConstantValue("-42");
913 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
914 JUnitTestCase.assertEquals(-42, value as int);
915 }
916
917 Object _getConstantValue(String source) => ParserTestCase.parseExpression(sour ce, []).accept(new ConstantEvaluator());
918
919 static dartSuite() {
920 _ut.group('ConstantEvaluatorTest', () {
921 _ut.test('test_binary_bitAnd', () {
922 final __test = new ConstantEvaluatorTest();
923 runJUnitTest(__test, __test.test_binary_bitAnd);
924 });
925 _ut.test('test_binary_bitOr', () {
926 final __test = new ConstantEvaluatorTest();
927 runJUnitTest(__test, __test.test_binary_bitOr);
928 });
929 _ut.test('test_binary_bitXor', () {
930 final __test = new ConstantEvaluatorTest();
931 runJUnitTest(__test, __test.test_binary_bitXor);
932 });
933 _ut.test('test_binary_divide_double', () {
934 final __test = new ConstantEvaluatorTest();
935 runJUnitTest(__test, __test.test_binary_divide_double);
936 });
937 _ut.test('test_binary_divide_integer', () {
938 final __test = new ConstantEvaluatorTest();
939 runJUnitTest(__test, __test.test_binary_divide_integer);
940 });
941 _ut.test('test_binary_equal_boolean', () {
942 final __test = new ConstantEvaluatorTest();
943 runJUnitTest(__test, __test.test_binary_equal_boolean);
944 });
945 _ut.test('test_binary_equal_integer', () {
946 final __test = new ConstantEvaluatorTest();
947 runJUnitTest(__test, __test.test_binary_equal_integer);
948 });
949 _ut.test('test_binary_equal_invalidLeft', () {
950 final __test = new ConstantEvaluatorTest();
951 runJUnitTest(__test, __test.test_binary_equal_invalidLeft);
952 });
953 _ut.test('test_binary_equal_invalidRight', () {
954 final __test = new ConstantEvaluatorTest();
955 runJUnitTest(__test, __test.test_binary_equal_invalidRight);
956 });
957 _ut.test('test_binary_equal_string', () {
958 final __test = new ConstantEvaluatorTest();
959 runJUnitTest(__test, __test.test_binary_equal_string);
960 });
961 _ut.test('test_binary_greaterThan', () {
962 final __test = new ConstantEvaluatorTest();
963 runJUnitTest(__test, __test.test_binary_greaterThan);
964 });
965 _ut.test('test_binary_greaterThanOrEqual', () {
966 final __test = new ConstantEvaluatorTest();
967 runJUnitTest(__test, __test.test_binary_greaterThanOrEqual);
968 });
969 _ut.test('test_binary_leftShift', () {
970 final __test = new ConstantEvaluatorTest();
971 runJUnitTest(__test, __test.test_binary_leftShift);
972 });
973 _ut.test('test_binary_lessThan', () {
974 final __test = new ConstantEvaluatorTest();
975 runJUnitTest(__test, __test.test_binary_lessThan);
976 });
977 _ut.test('test_binary_lessThanOrEqual', () {
978 final __test = new ConstantEvaluatorTest();
979 runJUnitTest(__test, __test.test_binary_lessThanOrEqual);
980 });
981 _ut.test('test_binary_logicalAnd', () {
982 final __test = new ConstantEvaluatorTest();
983 runJUnitTest(__test, __test.test_binary_logicalAnd);
984 });
985 _ut.test('test_binary_logicalOr', () {
986 final __test = new ConstantEvaluatorTest();
987 runJUnitTest(__test, __test.test_binary_logicalOr);
988 });
989 _ut.test('test_binary_minus_double', () {
990 final __test = new ConstantEvaluatorTest();
991 runJUnitTest(__test, __test.test_binary_minus_double);
992 });
993 _ut.test('test_binary_minus_integer', () {
994 final __test = new ConstantEvaluatorTest();
995 runJUnitTest(__test, __test.test_binary_minus_integer);
996 });
997 _ut.test('test_binary_notEqual_boolean', () {
998 final __test = new ConstantEvaluatorTest();
999 runJUnitTest(__test, __test.test_binary_notEqual_boolean);
1000 });
1001 _ut.test('test_binary_notEqual_integer', () {
1002 final __test = new ConstantEvaluatorTest();
1003 runJUnitTest(__test, __test.test_binary_notEqual_integer);
1004 });
1005 _ut.test('test_binary_notEqual_invalidLeft', () {
1006 final __test = new ConstantEvaluatorTest();
1007 runJUnitTest(__test, __test.test_binary_notEqual_invalidLeft);
1008 });
1009 _ut.test('test_binary_notEqual_invalidRight', () {
1010 final __test = new ConstantEvaluatorTest();
1011 runJUnitTest(__test, __test.test_binary_notEqual_invalidRight);
1012 });
1013 _ut.test('test_binary_notEqual_string', () {
1014 final __test = new ConstantEvaluatorTest();
1015 runJUnitTest(__test, __test.test_binary_notEqual_string);
1016 });
1017 _ut.test('test_binary_plus_double', () {
1018 final __test = new ConstantEvaluatorTest();
1019 runJUnitTest(__test, __test.test_binary_plus_double);
1020 });
1021 _ut.test('test_binary_plus_integer', () {
1022 final __test = new ConstantEvaluatorTest();
1023 runJUnitTest(__test, __test.test_binary_plus_integer);
1024 });
1025 _ut.test('test_binary_remainder_double', () {
1026 final __test = new ConstantEvaluatorTest();
1027 runJUnitTest(__test, __test.test_binary_remainder_double);
1028 });
1029 _ut.test('test_binary_remainder_integer', () {
1030 final __test = new ConstantEvaluatorTest();
1031 runJUnitTest(__test, __test.test_binary_remainder_integer);
1032 });
1033 _ut.test('test_binary_rightShift', () {
1034 final __test = new ConstantEvaluatorTest();
1035 runJUnitTest(__test, __test.test_binary_rightShift);
1036 });
1037 _ut.test('test_binary_times_double', () {
1038 final __test = new ConstantEvaluatorTest();
1039 runJUnitTest(__test, __test.test_binary_times_double);
1040 });
1041 _ut.test('test_binary_times_integer', () {
1042 final __test = new ConstantEvaluatorTest();
1043 runJUnitTest(__test, __test.test_binary_times_integer);
1044 });
1045 _ut.test('test_binary_truncatingDivide_double', () {
1046 final __test = new ConstantEvaluatorTest();
1047 runJUnitTest(__test, __test.test_binary_truncatingDivide_double);
1048 });
1049 _ut.test('test_binary_truncatingDivide_integer', () {
1050 final __test = new ConstantEvaluatorTest();
1051 runJUnitTest(__test, __test.test_binary_truncatingDivide_integer);
1052 });
1053 _ut.test('test_literal_boolean_false', () {
1054 final __test = new ConstantEvaluatorTest();
1055 runJUnitTest(__test, __test.test_literal_boolean_false);
1056 });
1057 _ut.test('test_literal_boolean_true', () {
1058 final __test = new ConstantEvaluatorTest();
1059 runJUnitTest(__test, __test.test_literal_boolean_true);
1060 });
1061 _ut.test('test_literal_list', () {
1062 final __test = new ConstantEvaluatorTest();
1063 runJUnitTest(__test, __test.test_literal_list);
1064 });
1065 _ut.test('test_literal_map', () {
1066 final __test = new ConstantEvaluatorTest();
1067 runJUnitTest(__test, __test.test_literal_map);
1068 });
1069 _ut.test('test_literal_null', () {
1070 final __test = new ConstantEvaluatorTest();
1071 runJUnitTest(__test, __test.test_literal_null);
1072 });
1073 _ut.test('test_literal_number_double', () {
1074 final __test = new ConstantEvaluatorTest();
1075 runJUnitTest(__test, __test.test_literal_number_double);
1076 });
1077 _ut.test('test_literal_number_integer', () {
1078 final __test = new ConstantEvaluatorTest();
1079 runJUnitTest(__test, __test.test_literal_number_integer);
1080 });
1081 _ut.test('test_literal_string_adjacent', () {
1082 final __test = new ConstantEvaluatorTest();
1083 runJUnitTest(__test, __test.test_literal_string_adjacent);
1084 });
1085 _ut.test('test_literal_string_interpolation_invalid', () {
1086 final __test = new ConstantEvaluatorTest();
1087 runJUnitTest(__test, __test.test_literal_string_interpolation_invalid);
1088 });
1089 _ut.test('test_literal_string_interpolation_valid', () {
1090 final __test = new ConstantEvaluatorTest();
1091 runJUnitTest(__test, __test.test_literal_string_interpolation_valid);
1092 });
1093 _ut.test('test_literal_string_simple', () {
1094 final __test = new ConstantEvaluatorTest();
1095 runJUnitTest(__test, __test.test_literal_string_simple);
1096 });
1097 _ut.test('test_parenthesizedExpression', () {
1098 final __test = new ConstantEvaluatorTest();
1099 runJUnitTest(__test, __test.test_parenthesizedExpression);
1100 });
1101 _ut.test('test_unary_bitNot', () {
1102 final __test = new ConstantEvaluatorTest();
1103 runJUnitTest(__test, __test.test_unary_bitNot);
1104 });
1105 _ut.test('test_unary_logicalNot', () {
1106 final __test = new ConstantEvaluatorTest();
1107 runJUnitTest(__test, __test.test_unary_logicalNot);
1108 });
1109 _ut.test('test_unary_negated_double', () {
1110 final __test = new ConstantEvaluatorTest();
1111 runJUnitTest(__test, __test.test_unary_negated_double);
1112 });
1113 _ut.test('test_unary_negated_integer', () {
1114 final __test = new ConstantEvaluatorTest();
1115 runJUnitTest(__test, __test.test_unary_negated_integer);
1116 });
1117 });
1118 }
1119 }
1120
1121 class IndexExpressionTest extends EngineTestCase {
1122 void test_inGetterContext_assignment_compound_left() {
1123 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
1124 // a[i] += ?
1125 AstFactory.assignmentExpression(expression, TokenType.PLUS_EQ, null);
1126 JUnitTestCase.assertTrue(expression.inGetterContext());
1127 }
1128
1129 void test_inGetterContext_assignment_simple_left() {
1130 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
1131 // a[i] = ?
1132 AstFactory.assignmentExpression(expression, TokenType.EQ, null);
1133 JUnitTestCase.assertFalse(expression.inGetterContext());
1134 }
1135
1136 void test_inGetterContext_nonAssignment() {
1137 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
1138 // a[i] + ?
1139 AstFactory.binaryExpression(expression, TokenType.PLUS, null);
1140 JUnitTestCase.assertTrue(expression.inGetterContext());
1141 }
1142
1143 void test_inSetterContext_assignment_compound_left() {
1144 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
1145 // a[i] += ?
1146 AstFactory.assignmentExpression(expression, TokenType.PLUS_EQ, null);
1147 JUnitTestCase.assertTrue(expression.inSetterContext());
1148 }
1149
1150 void test_inSetterContext_assignment_compound_right() {
1151 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
1152 // ? += a[i]
1153 AstFactory.assignmentExpression(null, TokenType.PLUS_EQ, expression);
1154 JUnitTestCase.assertFalse(expression.inSetterContext());
1155 }
1156
1157 void test_inSetterContext_assignment_simple_left() {
1158 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
1159 // a[i] = ?
1160 AstFactory.assignmentExpression(expression, TokenType.EQ, null);
1161 JUnitTestCase.assertTrue(expression.inSetterContext());
1162 }
1163
1164 void test_inSetterContext_assignment_simple_right() {
1165 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
1166 // ? = a[i]
1167 AstFactory.assignmentExpression(null, TokenType.EQ, expression);
1168 JUnitTestCase.assertFalse(expression.inSetterContext());
1169 }
1170
1171 void test_inSetterContext_nonAssignment() {
1172 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
1173 AstFactory.binaryExpression(expression, TokenType.PLUS, null);
1174 // a[i] + ?
1175 JUnitTestCase.assertFalse(expression.inSetterContext());
1176 }
1177
1178 void test_inSetterContext_postfix() {
1179 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
1180 AstFactory.postfixExpression(expression, TokenType.PLUS_PLUS);
1181 // a[i]++
1182 JUnitTestCase.assertTrue(expression.inSetterContext());
1183 }
1184
1185 void test_inSetterContext_prefix_bang() {
1186 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
1187 // !a[i]
1188 AstFactory.prefixExpression(TokenType.BANG, expression);
1189 JUnitTestCase.assertFalse(expression.inSetterContext());
1190 }
1191
1192 void test_inSetterContext_prefix_minusMinus() {
1193 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
1194 // --a[i]
1195 AstFactory.prefixExpression(TokenType.MINUS_MINUS, expression);
1196 JUnitTestCase.assertTrue(expression.inSetterContext());
1197 }
1198
1199 void test_inSetterContext_prefix_plusPlus() {
1200 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
1201 // ++a[i]
1202 AstFactory.prefixExpression(TokenType.PLUS_PLUS, expression);
1203 JUnitTestCase.assertTrue(expression.inSetterContext());
1204 }
1205
1206 static dartSuite() {
1207 _ut.group('IndexExpressionTest', () {
1208 _ut.test('test_inGetterContext_assignment_compound_left', () {
1209 final __test = new IndexExpressionTest();
1210 runJUnitTest(__test, __test.test_inGetterContext_assignment_compound_lef t);
1211 });
1212 _ut.test('test_inGetterContext_assignment_simple_left', () {
1213 final __test = new IndexExpressionTest();
1214 runJUnitTest(__test, __test.test_inGetterContext_assignment_simple_left) ;
1215 });
1216 _ut.test('test_inGetterContext_nonAssignment', () {
1217 final __test = new IndexExpressionTest();
1218 runJUnitTest(__test, __test.test_inGetterContext_nonAssignment);
1219 });
1220 _ut.test('test_inSetterContext_assignment_compound_left', () {
1221 final __test = new IndexExpressionTest();
1222 runJUnitTest(__test, __test.test_inSetterContext_assignment_compound_lef t);
1223 });
1224 _ut.test('test_inSetterContext_assignment_compound_right', () {
1225 final __test = new IndexExpressionTest();
1226 runJUnitTest(__test, __test.test_inSetterContext_assignment_compound_rig ht);
1227 });
1228 _ut.test('test_inSetterContext_assignment_simple_left', () {
1229 final __test = new IndexExpressionTest();
1230 runJUnitTest(__test, __test.test_inSetterContext_assignment_simple_left) ;
1231 });
1232 _ut.test('test_inSetterContext_assignment_simple_right', () {
1233 final __test = new IndexExpressionTest();
1234 runJUnitTest(__test, __test.test_inSetterContext_assignment_simple_right );
1235 });
1236 _ut.test('test_inSetterContext_nonAssignment', () {
1237 final __test = new IndexExpressionTest();
1238 runJUnitTest(__test, __test.test_inSetterContext_nonAssignment);
1239 });
1240 _ut.test('test_inSetterContext_postfix', () {
1241 final __test = new IndexExpressionTest();
1242 runJUnitTest(__test, __test.test_inSetterContext_postfix);
1243 });
1244 _ut.test('test_inSetterContext_prefix_bang', () {
1245 final __test = new IndexExpressionTest();
1246 runJUnitTest(__test, __test.test_inSetterContext_prefix_bang);
1247 });
1248 _ut.test('test_inSetterContext_prefix_minusMinus', () {
1249 final __test = new IndexExpressionTest();
1250 runJUnitTest(__test, __test.test_inSetterContext_prefix_minusMinus);
1251 });
1252 _ut.test('test_inSetterContext_prefix_plusPlus', () {
1253 final __test = new IndexExpressionTest();
1254 runJUnitTest(__test, __test.test_inSetterContext_prefix_plusPlus);
1255 });
1256 });
1257 }
1258 }
1259
1260 class NodeListTest extends EngineTestCase {
1261 void test_add() {
1262 AstNode parent = AstFactory.argumentList([]);
1263 AstNode firstNode = AstFactory.booleanLiteral(true);
1264 AstNode secondNode = AstFactory.booleanLiteral(false);
1265 NodeList<AstNode> list = new NodeList<AstNode>(parent);
1266 list.insert(0, secondNode);
1267 list.insert(0, firstNode);
1268 EngineTestCase.assertSizeOfList(2, list);
1269 JUnitTestCase.assertSame(firstNode, list[0]);
1270 JUnitTestCase.assertSame(secondNode, list[1]);
1271 JUnitTestCase.assertSame(parent, firstNode.parent);
1272 JUnitTestCase.assertSame(parent, secondNode.parent);
1273 AstNode thirdNode = AstFactory.booleanLiteral(false);
1274 list.insert(1, thirdNode);
1275 EngineTestCase.assertSizeOfList(3, list);
1276 JUnitTestCase.assertSame(firstNode, list[0]);
1277 JUnitTestCase.assertSame(thirdNode, list[1]);
1278 JUnitTestCase.assertSame(secondNode, list[2]);
1279 JUnitTestCase.assertSame(parent, firstNode.parent);
1280 JUnitTestCase.assertSame(parent, secondNode.parent);
1281 JUnitTestCase.assertSame(parent, thirdNode.parent);
1282 }
1283
1284 void test_add_negative() {
1285 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
1286 try {
1287 list.insert(-1, AstFactory.booleanLiteral(true));
1288 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
1289 } on RangeError catch (exception) {
1290 }
1291 }
1292
1293 void test_add_tooBig() {
1294 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
1295 try {
1296 list.insert(1, AstFactory.booleanLiteral(true));
1297 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
1298 } on RangeError catch (exception) {
1299 }
1300 }
1301
1302 void test_addAll() {
1303 AstNode parent = AstFactory.argumentList([]);
1304 List<AstNode> firstNodes = new List<AstNode>();
1305 AstNode firstNode = AstFactory.booleanLiteral(true);
1306 AstNode secondNode = AstFactory.booleanLiteral(false);
1307 firstNodes.add(firstNode);
1308 firstNodes.add(secondNode);
1309 NodeList<AstNode> list = new NodeList<AstNode>(parent);
1310 list.addAll(firstNodes);
1311 EngineTestCase.assertSizeOfList(2, list);
1312 JUnitTestCase.assertSame(firstNode, list[0]);
1313 JUnitTestCase.assertSame(secondNode, list[1]);
1314 JUnitTestCase.assertSame(parent, firstNode.parent);
1315 JUnitTestCase.assertSame(parent, secondNode.parent);
1316 List<AstNode> secondNodes = new List<AstNode>();
1317 AstNode thirdNode = AstFactory.booleanLiteral(true);
1318 AstNode fourthNode = AstFactory.booleanLiteral(false);
1319 secondNodes.add(thirdNode);
1320 secondNodes.add(fourthNode);
1321 list.addAll(secondNodes);
1322 EngineTestCase.assertSizeOfList(4, list);
1323 JUnitTestCase.assertSame(firstNode, list[0]);
1324 JUnitTestCase.assertSame(secondNode, list[1]);
1325 JUnitTestCase.assertSame(thirdNode, list[2]);
1326 JUnitTestCase.assertSame(fourthNode, list[3]);
1327 JUnitTestCase.assertSame(parent, firstNode.parent);
1328 JUnitTestCase.assertSame(parent, secondNode.parent);
1329 JUnitTestCase.assertSame(parent, thirdNode.parent);
1330 JUnitTestCase.assertSame(parent, fourthNode.parent);
1331 }
1332
1333 void test_create() {
1334 AstNode owner = AstFactory.argumentList([]);
1335 NodeList<AstNode> list = NodeList.create(owner);
1336 JUnitTestCase.assertNotNull(list);
1337 EngineTestCase.assertSizeOfList(0, list);
1338 JUnitTestCase.assertSame(owner, list.owner);
1339 }
1340
1341 void test_creation() {
1342 AstNode owner = AstFactory.argumentList([]);
1343 NodeList<AstNode> list = new NodeList<AstNode>(owner);
1344 JUnitTestCase.assertNotNull(list);
1345 EngineTestCase.assertSizeOfList(0, list);
1346 JUnitTestCase.assertSame(owner, list.owner);
1347 }
1348
1349 void test_get_negative() {
1350 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
1351 try {
1352 list[-1];
1353 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
1354 } on RangeError catch (exception) {
1355 }
1356 }
1357
1358 void test_get_tooBig() {
1359 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
1360 try {
1361 list[1];
1362 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
1363 } on RangeError catch (exception) {
1364 }
1365 }
1366
1367 void test_getBeginToken_empty() {
1368 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
1369 JUnitTestCase.assertNull(list.beginToken);
1370 }
1371
1372 void test_getBeginToken_nonEmpty() {
1373 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
1374 AstNode node = AstFactory.parenthesizedExpression(AstFactory.booleanLiteral( true));
1375 list.add(node);
1376 JUnitTestCase.assertSame(node.beginToken, list.beginToken);
1377 }
1378
1379 void test_getEndToken_empty() {
1380 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
1381 JUnitTestCase.assertNull(list.endToken);
1382 }
1383
1384 void test_getEndToken_nonEmpty() {
1385 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
1386 AstNode node = AstFactory.parenthesizedExpression(AstFactory.booleanLiteral( true));
1387 list.add(node);
1388 JUnitTestCase.assertSame(node.endToken, list.endToken);
1389 }
1390
1391 void test_indexOf() {
1392 List<AstNode> nodes = new List<AstNode>();
1393 AstNode firstNode = AstFactory.booleanLiteral(true);
1394 AstNode secondNode = AstFactory.booleanLiteral(false);
1395 AstNode thirdNode = AstFactory.booleanLiteral(true);
1396 AstNode fourthNode = AstFactory.booleanLiteral(false);
1397 nodes.add(firstNode);
1398 nodes.add(secondNode);
1399 nodes.add(thirdNode);
1400 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
1401 list.addAll(nodes);
1402 EngineTestCase.assertSizeOfList(3, list);
1403 JUnitTestCase.assertEquals(0, list.indexOf(firstNode));
1404 JUnitTestCase.assertEquals(1, list.indexOf(secondNode));
1405 JUnitTestCase.assertEquals(2, list.indexOf(thirdNode));
1406 JUnitTestCase.assertEquals(-1, list.indexOf(fourthNode));
1407 JUnitTestCase.assertEquals(-1, list.indexOf(null));
1408 }
1409
1410 void test_remove() {
1411 List<AstNode> nodes = new List<AstNode>();
1412 AstNode firstNode = AstFactory.booleanLiteral(true);
1413 AstNode secondNode = AstFactory.booleanLiteral(false);
1414 AstNode thirdNode = AstFactory.booleanLiteral(true);
1415 nodes.add(firstNode);
1416 nodes.add(secondNode);
1417 nodes.add(thirdNode);
1418 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
1419 list.addAll(nodes);
1420 EngineTestCase.assertSizeOfList(3, list);
1421 JUnitTestCase.assertSame(secondNode, list.removeAt(1));
1422 EngineTestCase.assertSizeOfList(2, list);
1423 JUnitTestCase.assertSame(firstNode, list[0]);
1424 JUnitTestCase.assertSame(thirdNode, list[1]);
1425 }
1426
1427 void test_remove_negative() {
1428 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
1429 try {
1430 list.removeAt(-1);
1431 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
1432 } on RangeError catch (exception) {
1433 }
1434 }
1435
1436 void test_remove_tooBig() {
1437 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
1438 try {
1439 list.removeAt(1);
1440 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
1441 } on RangeError catch (exception) {
1442 }
1443 }
1444
1445 void test_set() {
1446 List<AstNode> nodes = new List<AstNode>();
1447 AstNode firstNode = AstFactory.booleanLiteral(true);
1448 AstNode secondNode = AstFactory.booleanLiteral(false);
1449 AstNode thirdNode = AstFactory.booleanLiteral(true);
1450 nodes.add(firstNode);
1451 nodes.add(secondNode);
1452 nodes.add(thirdNode);
1453 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
1454 list.addAll(nodes);
1455 EngineTestCase.assertSizeOfList(3, list);
1456 AstNode fourthNode = AstFactory.integer(0);
1457 JUnitTestCase.assertSame(secondNode, javaListSet(list, 1, fourthNode));
1458 EngineTestCase.assertSizeOfList(3, list);
1459 JUnitTestCase.assertSame(firstNode, list[0]);
1460 JUnitTestCase.assertSame(fourthNode, list[1]);
1461 JUnitTestCase.assertSame(thirdNode, list[2]);
1462 }
1463
1464 void test_set_negative() {
1465 AstNode node = AstFactory.booleanLiteral(true);
1466 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
1467 try {
1468 javaListSet(list, -1, node);
1469 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
1470 } on RangeError catch (exception) {
1471 }
1472 }
1473
1474 void test_set_tooBig() {
1475 AstNode node = AstFactory.booleanLiteral(true);
1476 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
1477 try {
1478 javaListSet(list, 1, node);
1479 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
1480 } on RangeError catch (exception) {
1481 }
1482 }
1483
1484 static dartSuite() {
1485 _ut.group('NodeListTest', () {
1486 _ut.test('test_add', () {
1487 final __test = new NodeListTest();
1488 runJUnitTest(__test, __test.test_add);
1489 });
1490 _ut.test('test_addAll', () {
1491 final __test = new NodeListTest();
1492 runJUnitTest(__test, __test.test_addAll);
1493 });
1494 _ut.test('test_add_negative', () {
1495 final __test = new NodeListTest();
1496 runJUnitTest(__test, __test.test_add_negative);
1497 });
1498 _ut.test('test_add_tooBig', () {
1499 final __test = new NodeListTest();
1500 runJUnitTest(__test, __test.test_add_tooBig);
1501 });
1502 _ut.test('test_create', () {
1503 final __test = new NodeListTest();
1504 runJUnitTest(__test, __test.test_create);
1505 });
1506 _ut.test('test_creation', () {
1507 final __test = new NodeListTest();
1508 runJUnitTest(__test, __test.test_creation);
1509 });
1510 _ut.test('test_getBeginToken_empty', () {
1511 final __test = new NodeListTest();
1512 runJUnitTest(__test, __test.test_getBeginToken_empty);
1513 });
1514 _ut.test('test_getBeginToken_nonEmpty', () {
1515 final __test = new NodeListTest();
1516 runJUnitTest(__test, __test.test_getBeginToken_nonEmpty);
1517 });
1518 _ut.test('test_getEndToken_empty', () {
1519 final __test = new NodeListTest();
1520 runJUnitTest(__test, __test.test_getEndToken_empty);
1521 });
1522 _ut.test('test_getEndToken_nonEmpty', () {
1523 final __test = new NodeListTest();
1524 runJUnitTest(__test, __test.test_getEndToken_nonEmpty);
1525 });
1526 _ut.test('test_get_negative', () {
1527 final __test = new NodeListTest();
1528 runJUnitTest(__test, __test.test_get_negative);
1529 });
1530 _ut.test('test_get_tooBig', () {
1531 final __test = new NodeListTest();
1532 runJUnitTest(__test, __test.test_get_tooBig);
1533 });
1534 _ut.test('test_indexOf', () {
1535 final __test = new NodeListTest();
1536 runJUnitTest(__test, __test.test_indexOf);
1537 });
1538 _ut.test('test_remove', () {
1539 final __test = new NodeListTest();
1540 runJUnitTest(__test, __test.test_remove);
1541 });
1542 _ut.test('test_remove_negative', () {
1543 final __test = new NodeListTest();
1544 runJUnitTest(__test, __test.test_remove_negative);
1545 });
1546 _ut.test('test_remove_tooBig', () {
1547 final __test = new NodeListTest();
1548 runJUnitTest(__test, __test.test_remove_tooBig);
1549 });
1550 _ut.test('test_set', () {
1551 final __test = new NodeListTest();
1552 runJUnitTest(__test, __test.test_set);
1553 });
1554 _ut.test('test_set_negative', () {
1555 final __test = new NodeListTest();
1556 runJUnitTest(__test, __test.test_set_negative);
1557 });
1558 _ut.test('test_set_tooBig', () {
1559 final __test = new NodeListTest();
1560 runJUnitTest(__test, __test.test_set_tooBig);
1561 });
1562 });
1563 }
1564 }
1565
1566 class NodeLocatorTest extends ParserTestCase {
1567 void test_range() {
1568 CompilationUnit unit = ParserTestCase.parseCompilationUnit("library myLib;", []);
1569 _assertLocate(unit, 4, 10, (node) => node is LibraryDirective, LibraryDirect ive);
1570 }
1571
1572 void test_searchWithin_null() {
1573 NodeLocator locator = new NodeLocator.con2(0, 0);
1574 JUnitTestCase.assertNull(locator.searchWithin(null));
1575 }
1576
1577 void test_searchWithin_offset() {
1578 CompilationUnit unit = ParserTestCase.parseCompilationUnit("library myLib;", []);
1579 _assertLocate(unit, 10, 10, (node) => node is SimpleIdentifier, SimpleIdenti fier);
1580 }
1581
1582 void test_searchWithin_offsetAfterNode() {
1583 CompilationUnit unit = ParserTestCase.parseCompilationUnit(EngineTestCase.cr eateSource(["class A {}", "class B {}"]), []);
1584 NodeLocator locator = new NodeLocator.con2(1024, 1024);
1585 AstNode node = locator.searchWithin(unit.declarations[0]);
1586 JUnitTestCase.assertNull(node);
1587 }
1588
1589 void test_searchWithin_offsetBeforeNode() {
1590 CompilationUnit unit = ParserTestCase.parseCompilationUnit(EngineTestCase.cr eateSource(["class A {}", "class B {}"]), []);
1591 NodeLocator locator = new NodeLocator.con2(0, 0);
1592 AstNode node = locator.searchWithin(unit.declarations[1]);
1593 JUnitTestCase.assertNull(node);
1594 }
1595
1596 void _assertLocate(CompilationUnit unit, int start, int end, Predicate<AstNode > predicate, Type expectedClass) {
1597 NodeLocator locator = new NodeLocator.con2(start, end);
1598 AstNode node = locator.searchWithin(unit);
1599 JUnitTestCase.assertNotNull(node);
1600 JUnitTestCase.assertSame(node, locator.foundNode);
1601 JUnitTestCase.assertTrueMsg("Node starts after range", node.offset <= start) ;
1602 JUnitTestCase.assertTrueMsg("Node ends before range", node.offset + node.len gth > end);
1603 EngineTestCase.assertInstanceOf(predicate, expectedClass, node);
1604 }
1605
1606 static dartSuite() {
1607 _ut.group('NodeLocatorTest', () {
1608 _ut.test('test_range', () {
1609 final __test = new NodeLocatorTest();
1610 runJUnitTest(__test, __test.test_range);
1611 });
1612 _ut.test('test_searchWithin_null', () {
1613 final __test = new NodeLocatorTest();
1614 runJUnitTest(__test, __test.test_searchWithin_null);
1615 });
1616 _ut.test('test_searchWithin_offset', () {
1617 final __test = new NodeLocatorTest();
1618 runJUnitTest(__test, __test.test_searchWithin_offset);
1619 });
1620 _ut.test('test_searchWithin_offsetAfterNode', () {
1621 final __test = new NodeLocatorTest();
1622 runJUnitTest(__test, __test.test_searchWithin_offsetAfterNode);
1623 });
1624 _ut.test('test_searchWithin_offsetBeforeNode', () {
1625 final __test = new NodeLocatorTest();
1626 runJUnitTest(__test, __test.test_searchWithin_offsetBeforeNode);
1627 });
1628 });
1629 }
1630 }
1631
23 class SimpleIdentifierTest extends ParserTestCase { 1632 class SimpleIdentifierTest extends ParserTestCase {
24 void test_inDeclarationContext_argumentDefinition() { 1633 void test_inDeclarationContext_argumentDefinition() {
25 SimpleIdentifier identifier = AstFactory.argumentDefinitionTest("p").identif ier; 1634 SimpleIdentifier identifier = AstFactory.argumentDefinitionTest("p").identif ier;
26 JUnitTestCase.assertFalse(identifier.inDeclarationContext()); 1635 JUnitTestCase.assertFalse(identifier.inDeclarationContext());
27 } 1636 }
28 1637
29 void test_inDeclarationContext_catch_exception() { 1638 void test_inDeclarationContext_catch_exception() {
30 SimpleIdentifier identifier = AstFactory.catchClause("e", []).exceptionParam eter; 1639 SimpleIdentifier identifier = AstFactory.catchClause("e", []).exceptionParam eter;
31 JUnitTestCase.assertTrue(identifier.inDeclarationContext()); 1640 JUnitTestCase.assertTrue(identifier.inDeclarationContext());
32 } 1641 }
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 runJUnitTest(__test, __test.test_inReferenceContext); 1899 runJUnitTest(__test, __test.test_inReferenceContext);
291 }); 1900 });
292 _ut.test('test_inSetterContext', () { 1901 _ut.test('test_inSetterContext', () {
293 final __test = new SimpleIdentifierTest(); 1902 final __test = new SimpleIdentifierTest();
294 runJUnitTest(__test, __test.test_inSetterContext); 1903 runJUnitTest(__test, __test.test_inSetterContext);
295 }); 1904 });
296 }); 1905 });
297 } 1906 }
298 } 1907 }
299 1908
300 class AssignmentKind extends Enum<AssignmentKind> {
301 static const AssignmentKind BINARY = const AssignmentKind('BINARY', 0);
302
303 static const AssignmentKind COMPOUND_LEFT = const AssignmentKind('COMPOUND_LEF T', 1);
304
305 static const AssignmentKind COMPOUND_RIGHT = const AssignmentKind('COMPOUND_RI GHT', 2);
306
307 static const AssignmentKind POSTFIX_INC = const AssignmentKind('POSTFIX_INC', 3);
308
309 static const AssignmentKind PREFIX_DEC = const AssignmentKind('PREFIX_DEC', 4) ;
310
311 static const AssignmentKind PREFIX_INC = const AssignmentKind('PREFIX_INC', 5) ;
312
313 static const AssignmentKind PREFIX_NOT = const AssignmentKind('PREFIX_NOT', 6) ;
314
315 static const AssignmentKind SIMPLE_LEFT = const AssignmentKind('SIMPLE_LEFT', 7);
316
317 static const AssignmentKind SIMPLE_RIGHT = const AssignmentKind('SIMPLE_RIGHT' , 8);
318
319 static const AssignmentKind NONE = const AssignmentKind('NONE', 9);
320
321 static const List<AssignmentKind> values = const [
322 BINARY,
323 COMPOUND_LEFT,
324 COMPOUND_RIGHT,
325 POSTFIX_INC,
326 PREFIX_DEC,
327 PREFIX_INC,
328 PREFIX_NOT,
329 SIMPLE_LEFT,
330 SIMPLE_RIGHT,
331 NONE];
332
333 const AssignmentKind(String name, int ordinal) : super(name, ordinal);
334 }
335
336 class WrapperKind extends Enum<WrapperKind> {
337 static const WrapperKind PREFIXED_LEFT = const WrapperKind('PREFIXED_LEFT', 0) ;
338
339 static const WrapperKind PREFIXED_RIGHT = const WrapperKind('PREFIXED_RIGHT', 1);
340
341 static const WrapperKind PROPERTY_LEFT = const WrapperKind('PROPERTY_LEFT', 2) ;
342
343 static const WrapperKind PROPERTY_RIGHT = const WrapperKind('PROPERTY_RIGHT', 3);
344
345 static const WrapperKind NONE = const WrapperKind('NONE', 4);
346
347 static const List<WrapperKind> values = const [
348 PREFIXED_LEFT,
349 PREFIXED_RIGHT,
350 PROPERTY_LEFT,
351 PROPERTY_RIGHT,
352 NONE];
353
354 const WrapperKind(String name, int ordinal) : super(name, ordinal);
355 }
356
357 class SimpleStringLiteralTest extends ParserTestCase { 1909 class SimpleStringLiteralTest extends ParserTestCase {
358 void test_getValueOffset() { 1910 void test_getValueOffset() {
359 JUnitTestCase.assertEquals(1, new SimpleStringLiteral(TokenFactory.tokenFrom String("'X'"), "X").valueOffset); 1911 JUnitTestCase.assertEquals(1, new SimpleStringLiteral(TokenFactory.tokenFrom String("'X'"), "X").valueOffset);
360 JUnitTestCase.assertEquals(1, new SimpleStringLiteral(TokenFactory.tokenFrom String("\"X\""), "X").valueOffset); 1912 JUnitTestCase.assertEquals(1, new SimpleStringLiteral(TokenFactory.tokenFrom String("\"X\""), "X").valueOffset);
361 JUnitTestCase.assertEquals(3, new SimpleStringLiteral(TokenFactory.tokenFrom String("\"\"\"X\"\"\""), "X").valueOffset); 1913 JUnitTestCase.assertEquals(3, new SimpleStringLiteral(TokenFactory.tokenFrom String("\"\"\"X\"\"\""), "X").valueOffset);
362 JUnitTestCase.assertEquals(3, new SimpleStringLiteral(TokenFactory.tokenFrom String("'''X'''"), "X").valueOffset); 1914 JUnitTestCase.assertEquals(3, new SimpleStringLiteral(TokenFactory.tokenFrom String("'''X'''"), "X").valueOffset);
363 JUnitTestCase.assertEquals(2, new SimpleStringLiteral(TokenFactory.tokenFrom String("r'X'"), "X").valueOffset); 1915 JUnitTestCase.assertEquals(2, new SimpleStringLiteral(TokenFactory.tokenFrom String("r'X'"), "X").valueOffset);
364 JUnitTestCase.assertEquals(2, new SimpleStringLiteral(TokenFactory.tokenFrom String("r\"X\""), "X").valueOffset); 1916 JUnitTestCase.assertEquals(2, new SimpleStringLiteral(TokenFactory.tokenFrom String("r\"X\""), "X").valueOffset);
365 JUnitTestCase.assertEquals(4, new SimpleStringLiteral(TokenFactory.tokenFrom String("r\"\"\"X\"\"\""), "X").valueOffset); 1917 JUnitTestCase.assertEquals(4, new SimpleStringLiteral(TokenFactory.tokenFrom String("r\"\"\"X\"\"\""), "X").valueOffset);
366 JUnitTestCase.assertEquals(4, new SimpleStringLiteral(TokenFactory.tokenFrom String("r'''X'''"), "X").valueOffset); 1918 JUnitTestCase.assertEquals(4, new SimpleStringLiteral(TokenFactory.tokenFrom String("r'''X'''"), "X").valueOffset);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 runJUnitTest(__test, __test.test_isRaw); 1964 runJUnitTest(__test, __test.test_isRaw);
413 }); 1965 });
414 _ut.test('test_simple', () { 1966 _ut.test('test_simple', () {
415 final __test = new SimpleStringLiteralTest(); 1967 final __test = new SimpleStringLiteralTest();
416 runJUnitTest(__test, __test.test_simple); 1968 runJUnitTest(__test, __test.test_simple);
417 }); 1969 });
418 }); 1970 });
419 } 1971 }
420 } 1972 }
421 1973
422 class ConstantEvaluatorTest extends ParserTestCase {
423 void fail_constructor() {
424 Object value = _getConstantValue("?");
425 JUnitTestCase.assertEquals(null, value);
426 }
427
428 void fail_identifier_class() {
429 Object value = _getConstantValue("?");
430 JUnitTestCase.assertEquals(null, value);
431 }
432
433 void fail_identifier_function() {
434 Object value = _getConstantValue("?");
435 JUnitTestCase.assertEquals(null, value);
436 }
437
438 void fail_identifier_static() {
439 Object value = _getConstantValue("?");
440 JUnitTestCase.assertEquals(null, value);
441 }
442
443 void fail_identifier_staticMethod() {
444 Object value = _getConstantValue("?");
445 JUnitTestCase.assertEquals(null, value);
446 }
447
448 void fail_identifier_topLevel() {
449 Object value = _getConstantValue("?");
450 JUnitTestCase.assertEquals(null, value);
451 }
452
453 void fail_identifier_typeParameter() {
454 Object value = _getConstantValue("?");
455 JUnitTestCase.assertEquals(null, value);
456 }
457
458 void test_binary_bitAnd() {
459 Object value = _getConstantValue("74 & 42");
460 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
461 JUnitTestCase.assertEquals(74 & 42, value as int);
462 }
463
464 void test_binary_bitOr() {
465 Object value = _getConstantValue("74 | 42");
466 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
467 JUnitTestCase.assertEquals(74 | 42, value as int);
468 }
469
470 void test_binary_bitXor() {
471 Object value = _getConstantValue("74 ^ 42");
472 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
473 JUnitTestCase.assertEquals(74 ^ 42, value as int);
474 }
475
476 void test_binary_divide_double() {
477 Object value = _getConstantValue("3.2 / 2.3");
478 EngineTestCase.assertInstanceOf((obj) => obj is double, double, value);
479 JUnitTestCase.assertEquals(3.2 / 2.3, value as double);
480 }
481
482 void test_binary_divide_integer() {
483 Object value = _getConstantValue("3 / 2");
484 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
485 JUnitTestCase.assertEquals(1, value as int);
486 }
487
488 void test_binary_equal_boolean() {
489 Object value = _getConstantValue("true == false");
490 JUnitTestCase.assertEquals(false, value);
491 }
492
493 void test_binary_equal_integer() {
494 Object value = _getConstantValue("2 == 3");
495 JUnitTestCase.assertEquals(false, value);
496 }
497
498 void test_binary_equal_invalidLeft() {
499 Object value = _getConstantValue("a == 3");
500 JUnitTestCase.assertEquals(ConstantEvaluator.NOT_A_CONSTANT, value);
501 }
502
503 void test_binary_equal_invalidRight() {
504 Object value = _getConstantValue("2 == a");
505 JUnitTestCase.assertEquals(ConstantEvaluator.NOT_A_CONSTANT, value);
506 }
507
508 void test_binary_equal_string() {
509 Object value = _getConstantValue("'a' == 'b'");
510 JUnitTestCase.assertEquals(false, value);
511 }
512
513 void test_binary_greaterThan() {
514 Object value = _getConstantValue("2 > 3");
515 JUnitTestCase.assertEquals(false, value);
516 }
517
518 void test_binary_greaterThanOrEqual() {
519 Object value = _getConstantValue("2 >= 3");
520 JUnitTestCase.assertEquals(false, value);
521 }
522
523 void test_binary_leftShift() {
524 Object value = _getConstantValue("16 << 2");
525 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
526 JUnitTestCase.assertEquals(64, value as int);
527 }
528
529 void test_binary_lessThan() {
530 Object value = _getConstantValue("2 < 3");
531 JUnitTestCase.assertEquals(true, value);
532 }
533
534 void test_binary_lessThanOrEqual() {
535 Object value = _getConstantValue("2 <= 3");
536 JUnitTestCase.assertEquals(true, value);
537 }
538
539 void test_binary_logicalAnd() {
540 Object value = _getConstantValue("true && false");
541 JUnitTestCase.assertEquals(false, value);
542 }
543
544 void test_binary_logicalOr() {
545 Object value = _getConstantValue("true || false");
546 JUnitTestCase.assertEquals(true, value);
547 }
548
549 void test_binary_minus_double() {
550 Object value = _getConstantValue("3.2 - 2.3");
551 EngineTestCase.assertInstanceOf((obj) => obj is double, double, value);
552 JUnitTestCase.assertEquals(3.2 - 2.3, value as double);
553 }
554
555 void test_binary_minus_integer() {
556 Object value = _getConstantValue("3 - 2");
557 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
558 JUnitTestCase.assertEquals(1, value as int);
559 }
560
561 void test_binary_notEqual_boolean() {
562 Object value = _getConstantValue("true != false");
563 JUnitTestCase.assertEquals(true, value);
564 }
565
566 void test_binary_notEqual_integer() {
567 Object value = _getConstantValue("2 != 3");
568 JUnitTestCase.assertEquals(true, value);
569 }
570
571 void test_binary_notEqual_invalidLeft() {
572 Object value = _getConstantValue("a != 3");
573 JUnitTestCase.assertEquals(ConstantEvaluator.NOT_A_CONSTANT, value);
574 }
575
576 void test_binary_notEqual_invalidRight() {
577 Object value = _getConstantValue("2 != a");
578 JUnitTestCase.assertEquals(ConstantEvaluator.NOT_A_CONSTANT, value);
579 }
580
581 void test_binary_notEqual_string() {
582 Object value = _getConstantValue("'a' != 'b'");
583 JUnitTestCase.assertEquals(true, value);
584 }
585
586 void test_binary_plus_double() {
587 Object value = _getConstantValue("2.3 + 3.2");
588 EngineTestCase.assertInstanceOf((obj) => obj is double, double, value);
589 JUnitTestCase.assertEquals(2.3 + 3.2, value as double);
590 }
591
592 void test_binary_plus_integer() {
593 Object value = _getConstantValue("2 + 3");
594 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
595 JUnitTestCase.assertEquals(5, value as int);
596 }
597
598 void test_binary_remainder_double() {
599 Object value = _getConstantValue("3.2 % 2.3");
600 EngineTestCase.assertInstanceOf((obj) => obj is double, double, value);
601 JUnitTestCase.assertEquals(3.2 % 2.3, value as double);
602 }
603
604 void test_binary_remainder_integer() {
605 Object value = _getConstantValue("8 % 3");
606 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
607 JUnitTestCase.assertEquals(2, value as int);
608 }
609
610 void test_binary_rightShift() {
611 Object value = _getConstantValue("64 >> 2");
612 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
613 JUnitTestCase.assertEquals(16, value as int);
614 }
615
616 void test_binary_times_double() {
617 Object value = _getConstantValue("2.3 * 3.2");
618 EngineTestCase.assertInstanceOf((obj) => obj is double, double, value);
619 JUnitTestCase.assertEquals(2.3 * 3.2, value as double);
620 }
621
622 void test_binary_times_integer() {
623 Object value = _getConstantValue("2 * 3");
624 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
625 JUnitTestCase.assertEquals(6, value as int);
626 }
627
628 void test_binary_truncatingDivide_double() {
629 Object value = _getConstantValue("3.2 ~/ 2.3");
630 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
631 JUnitTestCase.assertEquals(1, value as int);
632 }
633
634 void test_binary_truncatingDivide_integer() {
635 Object value = _getConstantValue("10 ~/ 3");
636 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
637 JUnitTestCase.assertEquals(3, value as int);
638 }
639
640 void test_literal_boolean_false() {
641 Object value = _getConstantValue("false");
642 JUnitTestCase.assertEquals(false, value);
643 }
644
645 void test_literal_boolean_true() {
646 Object value = _getConstantValue("true");
647 JUnitTestCase.assertEquals(true, value);
648 }
649
650 void test_literal_list() {
651 Object value = _getConstantValue("['a', 'b', 'c']");
652 EngineTestCase.assertInstanceOf((obj) => obj is List, List, value);
653 List list = value as List;
654 JUnitTestCase.assertEquals(3, list.length);
655 JUnitTestCase.assertEquals("a", list[0]);
656 JUnitTestCase.assertEquals("b", list[1]);
657 JUnitTestCase.assertEquals("c", list[2]);
658 }
659
660 void test_literal_map() {
661 Object value = _getConstantValue("{'a' : 'm', 'b' : 'n', 'c' : 'o'}");
662 EngineTestCase.assertInstanceOf((obj) => obj is Map, Map, value);
663 Map map = value as Map;
664 JUnitTestCase.assertEquals(3, map.length);
665 JUnitTestCase.assertEquals("m", map["a"]);
666 JUnitTestCase.assertEquals("n", map["b"]);
667 JUnitTestCase.assertEquals("o", map["c"]);
668 }
669
670 void test_literal_null() {
671 Object value = _getConstantValue("null");
672 JUnitTestCase.assertEquals(null, value);
673 }
674
675 void test_literal_number_double() {
676 Object value = _getConstantValue("3.45");
677 EngineTestCase.assertInstanceOf((obj) => obj is double, double, value);
678 JUnitTestCase.assertEquals(3.45, value as double);
679 }
680
681 void test_literal_number_integer() {
682 Object value = _getConstantValue("42");
683 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
684 JUnitTestCase.assertEquals(42, value as int);
685 }
686
687 void test_literal_string_adjacent() {
688 Object value = _getConstantValue("'abc' 'def'");
689 JUnitTestCase.assertEquals("abcdef", value);
690 }
691
692 void test_literal_string_interpolation_invalid() {
693 Object value = _getConstantValue("'a\${f()}c'");
694 JUnitTestCase.assertEquals(ConstantEvaluator.NOT_A_CONSTANT, value);
695 }
696
697 void test_literal_string_interpolation_valid() {
698 Object value = _getConstantValue("'a\${3}c'");
699 JUnitTestCase.assertEquals("a3c", value);
700 }
701
702 void test_literal_string_simple() {
703 Object value = _getConstantValue("'abc'");
704 JUnitTestCase.assertEquals("abc", value);
705 }
706
707 void test_parenthesizedExpression() {
708 Object value = _getConstantValue("('a')");
709 JUnitTestCase.assertEquals("a", value);
710 }
711
712 void test_unary_bitNot() {
713 Object value = _getConstantValue("~42");
714 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
715 JUnitTestCase.assertEquals(~42, value as int);
716 }
717
718 void test_unary_logicalNot() {
719 Object value = _getConstantValue("!true");
720 JUnitTestCase.assertEquals(false, value);
721 }
722
723 void test_unary_negated_double() {
724 Object value = _getConstantValue("-42.3");
725 EngineTestCase.assertInstanceOf((obj) => obj is double, double, value);
726 JUnitTestCase.assertEquals(-42.3, value as double);
727 }
728
729 void test_unary_negated_integer() {
730 Object value = _getConstantValue("-42");
731 EngineTestCase.assertInstanceOf((obj) => obj is int, int, value);
732 JUnitTestCase.assertEquals(-42, value as int);
733 }
734
735 Object _getConstantValue(String source) => ParserTestCase.parseExpression(sour ce, []).accept(new ConstantEvaluator());
736
737 static dartSuite() {
738 _ut.group('ConstantEvaluatorTest', () {
739 _ut.test('test_binary_bitAnd', () {
740 final __test = new ConstantEvaluatorTest();
741 runJUnitTest(__test, __test.test_binary_bitAnd);
742 });
743 _ut.test('test_binary_bitOr', () {
744 final __test = new ConstantEvaluatorTest();
745 runJUnitTest(__test, __test.test_binary_bitOr);
746 });
747 _ut.test('test_binary_bitXor', () {
748 final __test = new ConstantEvaluatorTest();
749 runJUnitTest(__test, __test.test_binary_bitXor);
750 });
751 _ut.test('test_binary_divide_double', () {
752 final __test = new ConstantEvaluatorTest();
753 runJUnitTest(__test, __test.test_binary_divide_double);
754 });
755 _ut.test('test_binary_divide_integer', () {
756 final __test = new ConstantEvaluatorTest();
757 runJUnitTest(__test, __test.test_binary_divide_integer);
758 });
759 _ut.test('test_binary_equal_boolean', () {
760 final __test = new ConstantEvaluatorTest();
761 runJUnitTest(__test, __test.test_binary_equal_boolean);
762 });
763 _ut.test('test_binary_equal_integer', () {
764 final __test = new ConstantEvaluatorTest();
765 runJUnitTest(__test, __test.test_binary_equal_integer);
766 });
767 _ut.test('test_binary_equal_invalidLeft', () {
768 final __test = new ConstantEvaluatorTest();
769 runJUnitTest(__test, __test.test_binary_equal_invalidLeft);
770 });
771 _ut.test('test_binary_equal_invalidRight', () {
772 final __test = new ConstantEvaluatorTest();
773 runJUnitTest(__test, __test.test_binary_equal_invalidRight);
774 });
775 _ut.test('test_binary_equal_string', () {
776 final __test = new ConstantEvaluatorTest();
777 runJUnitTest(__test, __test.test_binary_equal_string);
778 });
779 _ut.test('test_binary_greaterThan', () {
780 final __test = new ConstantEvaluatorTest();
781 runJUnitTest(__test, __test.test_binary_greaterThan);
782 });
783 _ut.test('test_binary_greaterThanOrEqual', () {
784 final __test = new ConstantEvaluatorTest();
785 runJUnitTest(__test, __test.test_binary_greaterThanOrEqual);
786 });
787 _ut.test('test_binary_leftShift', () {
788 final __test = new ConstantEvaluatorTest();
789 runJUnitTest(__test, __test.test_binary_leftShift);
790 });
791 _ut.test('test_binary_lessThan', () {
792 final __test = new ConstantEvaluatorTest();
793 runJUnitTest(__test, __test.test_binary_lessThan);
794 });
795 _ut.test('test_binary_lessThanOrEqual', () {
796 final __test = new ConstantEvaluatorTest();
797 runJUnitTest(__test, __test.test_binary_lessThanOrEqual);
798 });
799 _ut.test('test_binary_logicalAnd', () {
800 final __test = new ConstantEvaluatorTest();
801 runJUnitTest(__test, __test.test_binary_logicalAnd);
802 });
803 _ut.test('test_binary_logicalOr', () {
804 final __test = new ConstantEvaluatorTest();
805 runJUnitTest(__test, __test.test_binary_logicalOr);
806 });
807 _ut.test('test_binary_minus_double', () {
808 final __test = new ConstantEvaluatorTest();
809 runJUnitTest(__test, __test.test_binary_minus_double);
810 });
811 _ut.test('test_binary_minus_integer', () {
812 final __test = new ConstantEvaluatorTest();
813 runJUnitTest(__test, __test.test_binary_minus_integer);
814 });
815 _ut.test('test_binary_notEqual_boolean', () {
816 final __test = new ConstantEvaluatorTest();
817 runJUnitTest(__test, __test.test_binary_notEqual_boolean);
818 });
819 _ut.test('test_binary_notEqual_integer', () {
820 final __test = new ConstantEvaluatorTest();
821 runJUnitTest(__test, __test.test_binary_notEqual_integer);
822 });
823 _ut.test('test_binary_notEqual_invalidLeft', () {
824 final __test = new ConstantEvaluatorTest();
825 runJUnitTest(__test, __test.test_binary_notEqual_invalidLeft);
826 });
827 _ut.test('test_binary_notEqual_invalidRight', () {
828 final __test = new ConstantEvaluatorTest();
829 runJUnitTest(__test, __test.test_binary_notEqual_invalidRight);
830 });
831 _ut.test('test_binary_notEqual_string', () {
832 final __test = new ConstantEvaluatorTest();
833 runJUnitTest(__test, __test.test_binary_notEqual_string);
834 });
835 _ut.test('test_binary_plus_double', () {
836 final __test = new ConstantEvaluatorTest();
837 runJUnitTest(__test, __test.test_binary_plus_double);
838 });
839 _ut.test('test_binary_plus_integer', () {
840 final __test = new ConstantEvaluatorTest();
841 runJUnitTest(__test, __test.test_binary_plus_integer);
842 });
843 _ut.test('test_binary_remainder_double', () {
844 final __test = new ConstantEvaluatorTest();
845 runJUnitTest(__test, __test.test_binary_remainder_double);
846 });
847 _ut.test('test_binary_remainder_integer', () {
848 final __test = new ConstantEvaluatorTest();
849 runJUnitTest(__test, __test.test_binary_remainder_integer);
850 });
851 _ut.test('test_binary_rightShift', () {
852 final __test = new ConstantEvaluatorTest();
853 runJUnitTest(__test, __test.test_binary_rightShift);
854 });
855 _ut.test('test_binary_times_double', () {
856 final __test = new ConstantEvaluatorTest();
857 runJUnitTest(__test, __test.test_binary_times_double);
858 });
859 _ut.test('test_binary_times_integer', () {
860 final __test = new ConstantEvaluatorTest();
861 runJUnitTest(__test, __test.test_binary_times_integer);
862 });
863 _ut.test('test_binary_truncatingDivide_double', () {
864 final __test = new ConstantEvaluatorTest();
865 runJUnitTest(__test, __test.test_binary_truncatingDivide_double);
866 });
867 _ut.test('test_binary_truncatingDivide_integer', () {
868 final __test = new ConstantEvaluatorTest();
869 runJUnitTest(__test, __test.test_binary_truncatingDivide_integer);
870 });
871 _ut.test('test_literal_boolean_false', () {
872 final __test = new ConstantEvaluatorTest();
873 runJUnitTest(__test, __test.test_literal_boolean_false);
874 });
875 _ut.test('test_literal_boolean_true', () {
876 final __test = new ConstantEvaluatorTest();
877 runJUnitTest(__test, __test.test_literal_boolean_true);
878 });
879 _ut.test('test_literal_list', () {
880 final __test = new ConstantEvaluatorTest();
881 runJUnitTest(__test, __test.test_literal_list);
882 });
883 _ut.test('test_literal_map', () {
884 final __test = new ConstantEvaluatorTest();
885 runJUnitTest(__test, __test.test_literal_map);
886 });
887 _ut.test('test_literal_null', () {
888 final __test = new ConstantEvaluatorTest();
889 runJUnitTest(__test, __test.test_literal_null);
890 });
891 _ut.test('test_literal_number_double', () {
892 final __test = new ConstantEvaluatorTest();
893 runJUnitTest(__test, __test.test_literal_number_double);
894 });
895 _ut.test('test_literal_number_integer', () {
896 final __test = new ConstantEvaluatorTest();
897 runJUnitTest(__test, __test.test_literal_number_integer);
898 });
899 _ut.test('test_literal_string_adjacent', () {
900 final __test = new ConstantEvaluatorTest();
901 runJUnitTest(__test, __test.test_literal_string_adjacent);
902 });
903 _ut.test('test_literal_string_interpolation_invalid', () {
904 final __test = new ConstantEvaluatorTest();
905 runJUnitTest(__test, __test.test_literal_string_interpolation_invalid);
906 });
907 _ut.test('test_literal_string_interpolation_valid', () {
908 final __test = new ConstantEvaluatorTest();
909 runJUnitTest(__test, __test.test_literal_string_interpolation_valid);
910 });
911 _ut.test('test_literal_string_simple', () {
912 final __test = new ConstantEvaluatorTest();
913 runJUnitTest(__test, __test.test_literal_string_simple);
914 });
915 _ut.test('test_parenthesizedExpression', () {
916 final __test = new ConstantEvaluatorTest();
917 runJUnitTest(__test, __test.test_parenthesizedExpression);
918 });
919 _ut.test('test_unary_bitNot', () {
920 final __test = new ConstantEvaluatorTest();
921 runJUnitTest(__test, __test.test_unary_bitNot);
922 });
923 _ut.test('test_unary_logicalNot', () {
924 final __test = new ConstantEvaluatorTest();
925 runJUnitTest(__test, __test.test_unary_logicalNot);
926 });
927 _ut.test('test_unary_negated_double', () {
928 final __test = new ConstantEvaluatorTest();
929 runJUnitTest(__test, __test.test_unary_negated_double);
930 });
931 _ut.test('test_unary_negated_integer', () {
932 final __test = new ConstantEvaluatorTest();
933 runJUnitTest(__test, __test.test_unary_negated_integer);
934 });
935 });
936 }
937 }
938
939 class ToSourceVisitorTest extends EngineTestCase { 1974 class ToSourceVisitorTest extends EngineTestCase {
940 void test_visitAdjacentStrings() { 1975 void test_visitAdjacentStrings() {
941 _assertSource("'a' 'b'", AstFactory.adjacentStrings([AstFactory.string2("a") , AstFactory.string2("b")])); 1976 _assertSource("'a' 'b'", AstFactory.adjacentStrings([AstFactory.string2("a") , AstFactory.string2("b")]));
942 } 1977 }
943 1978
944 void test_visitAnnotation_constant() { 1979 void test_visitAnnotation_constant() {
945 _assertSource("@A", AstFactory.annotation(AstFactory.identifier3("A"))); 1980 _assertSource("@A", AstFactory.annotation(AstFactory.identifier3("A")));
946 } 1981 }
947 1982
948 void test_visitAnnotation_constructor() { 1983 void test_visitAnnotation_constructor() {
(...skipping 2221 matching lines...) Expand 10 before | Expand all | Expand 10 after
3170 _ut.test('test_visitWithClause_multiple', () { 4205 _ut.test('test_visitWithClause_multiple', () {
3171 final __test = new ToSourceVisitorTest(); 4206 final __test = new ToSourceVisitorTest();
3172 runJUnitTest(__test, __test.test_visitWithClause_multiple); 4207 runJUnitTest(__test, __test.test_visitWithClause_multiple);
3173 }); 4208 });
3174 _ut.test('test_visitWithClause_single', () { 4209 _ut.test('test_visitWithClause_single', () {
3175 final __test = new ToSourceVisitorTest(); 4210 final __test = new ToSourceVisitorTest();
3176 runJUnitTest(__test, __test.test_visitWithClause_single); 4211 runJUnitTest(__test, __test.test_visitWithClause_single);
3177 }); 4212 });
3178 }); 4213 });
3179 } 4214 }
3180 }
3181
3182 class NodeLocatorTest extends ParserTestCase {
3183 void test_range() {
3184 CompilationUnit unit = ParserTestCase.parseCompilationUnit("library myLib;", []);
3185 _assertLocate(unit, 4, 10, (node) => node is LibraryDirective, LibraryDirect ive);
3186 }
3187
3188 void test_searchWithin_null() {
3189 NodeLocator locator = new NodeLocator.con2(0, 0);
3190 JUnitTestCase.assertNull(locator.searchWithin(null));
3191 }
3192
3193 void test_searchWithin_offset() {
3194 CompilationUnit unit = ParserTestCase.parseCompilationUnit("library myLib;", []);
3195 _assertLocate(unit, 10, 10, (node) => node is SimpleIdentifier, SimpleIdenti fier);
3196 }
3197
3198 void test_searchWithin_offsetAfterNode() {
3199 CompilationUnit unit = ParserTestCase.parseCompilationUnit(EngineTestCase.cr eateSource(["class A {}", "class B {}"]), []);
3200 NodeLocator locator = new NodeLocator.con2(1024, 1024);
3201 AstNode node = locator.searchWithin(unit.declarations[0]);
3202 JUnitTestCase.assertNull(node);
3203 }
3204
3205 void test_searchWithin_offsetBeforeNode() {
3206 CompilationUnit unit = ParserTestCase.parseCompilationUnit(EngineTestCase.cr eateSource(["class A {}", "class B {}"]), []);
3207 NodeLocator locator = new NodeLocator.con2(0, 0);
3208 AstNode node = locator.searchWithin(unit.declarations[1]);
3209 JUnitTestCase.assertNull(node);
3210 }
3211
3212 void _assertLocate(CompilationUnit unit, int start, int end, Predicate<AstNode > predicate, Type expectedClass) {
3213 NodeLocator locator = new NodeLocator.con2(start, end);
3214 AstNode node = locator.searchWithin(unit);
3215 JUnitTestCase.assertNotNull(node);
3216 JUnitTestCase.assertSame(node, locator.foundNode);
3217 JUnitTestCase.assertTrueMsg("Node starts after range", node.offset <= start) ;
3218 JUnitTestCase.assertTrueMsg("Node ends before range", node.offset + node.len gth > end);
3219 EngineTestCase.assertInstanceOf(predicate, expectedClass, node);
3220 }
3221
3222 static dartSuite() {
3223 _ut.group('NodeLocatorTest', () {
3224 _ut.test('test_range', () {
3225 final __test = new NodeLocatorTest();
3226 runJUnitTest(__test, __test.test_range);
3227 });
3228 _ut.test('test_searchWithin_null', () {
3229 final __test = new NodeLocatorTest();
3230 runJUnitTest(__test, __test.test_searchWithin_null);
3231 });
3232 _ut.test('test_searchWithin_offset', () {
3233 final __test = new NodeLocatorTest();
3234 runJUnitTest(__test, __test.test_searchWithin_offset);
3235 });
3236 _ut.test('test_searchWithin_offsetAfterNode', () {
3237 final __test = new NodeLocatorTest();
3238 runJUnitTest(__test, __test.test_searchWithin_offsetAfterNode);
3239 });
3240 _ut.test('test_searchWithin_offsetBeforeNode', () {
3241 final __test = new NodeLocatorTest();
3242 runJUnitTest(__test, __test.test_searchWithin_offsetBeforeNode);
3243 });
3244 });
3245 }
3246 }
3247
3248 /**
3249 * The class `AstFactory` defines utility methods that can be used to create AST nodes. The
3250 * nodes that are created are complete in the sense that all of the tokens that would have been
3251 * associated with the nodes by a parser are also created, but the token stream is not constructed.
3252 * None of the nodes are resolved.
3253 *
3254 * The general pattern is for the name of the factory method to be the same as t he name of the class
3255 * of AST node being created. There are two notable exceptions. The first is for methods creating
3256 * nodes that are part of a cascade expression. These methods are all prefixed w ith 'cascaded'. The
3257 * second is places where a shorter name seemed unambiguous and easier to read, such as using
3258 * 'identifier' rather than 'prefixedIdentifier', or 'integer' rather than 'inte gerLiteral'.
3259 */
3260 class AstFactory {
3261 static AdjacentStrings adjacentStrings(List<StringLiteral> strings) => new Adj acentStrings(list(strings));
3262
3263 static Annotation annotation(Identifier name) => new Annotation(TokenFactory.t okenFromType(TokenType.AT), name, null, null, null);
3264
3265 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);
3266
3267 static ArgumentDefinitionTest argumentDefinitionTest(String identifier) => new ArgumentDefinitionTest(TokenFactory.tokenFromType(TokenType.QUESTION), identifi er3(identifier));
3268
3269 static ArgumentList argumentList(List<Expression> arguments) => new ArgumentLi st(TokenFactory.tokenFromType(TokenType.OPEN_PAREN), list(arguments), TokenFacto ry.tokenFromType(TokenType.CLOSE_PAREN));
3270
3271 static AsExpression asExpression(Expression expression, TypeName type) => new AsExpression(expression, TokenFactory.tokenFromKeyword(Keyword.AS), type);
3272
3273 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));
3274
3275 static AssignmentExpression assignmentExpression(Expression leftHandSide, Toke nType operator, Expression rightHandSide) => new AssignmentExpression(leftHandSi de, TokenFactory.tokenFromType(operator), rightHandSide);
3276
3277 static BinaryExpression binaryExpression(Expression leftOperand, TokenType ope rator, Expression rightOperand) => new BinaryExpression(leftOperand, TokenFactor y.tokenFromType(operator), rightOperand);
3278
3279 static Block block(List<Statement> statements) => new Block(TokenFactory.token FromType(TokenType.OPEN_CURLY_BRACKET), list(statements), TokenFactory.tokenFrom Type(TokenType.CLOSE_CURLY_BRACKET));
3280
3281 static BlockFunctionBody blockFunctionBody(Block block) => new BlockFunctionBo dy(block);
3282
3283 static BlockFunctionBody blockFunctionBody2(List<Statement> statements) => new BlockFunctionBody(block(statements));
3284
3285 static BooleanLiteral booleanLiteral(bool value) => new BooleanLiteral(value ? TokenFactory.tokenFromKeyword(Keyword.TRUE) : TokenFactory.tokenFromKeyword(Key word.FALSE), value);
3286
3287 static BreakStatement breakStatement() => new BreakStatement(TokenFactory.toke nFromKeyword(Keyword.BREAK), null, TokenFactory.tokenFromType(TokenType.SEMICOLO N));
3288
3289 static BreakStatement breakStatement2(String label) => new BreakStatement(Toke nFactory.tokenFromKeyword(Keyword.BREAK), identifier3(label), TokenFactory.token FromType(TokenType.SEMICOLON));
3290
3291 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));
3292
3293 static MethodInvocation cascadedMethodInvocation(String methodName, List<Expre ssion> arguments) => new MethodInvocation(null, TokenFactory.tokenFromType(Token Type.PERIOD_PERIOD), identifier3(methodName), argumentList(arguments));
3294
3295 static PropertyAccess cascadedPropertyAccess(String propertyName) => new Prope rtyAccess(null, TokenFactory.tokenFromType(TokenType.PERIOD_PERIOD), identifier3 (propertyName));
3296
3297 static CascadeExpression cascadeExpression(Expression target, List<Expression> cascadeSections) => new CascadeExpression(target, list(cascadeSections));
3298
3299 static CatchClause catchClause(String exceptionParameter, List<Statement> stat ements) => catchClause5(null, exceptionParameter, null, statements);
3300
3301 static CatchClause catchClause2(String exceptionParameter, String stackTracePa rameter, List<Statement> statements) => catchClause5(null, exceptionParameter, s tackTraceParameter, statements);
3302
3303 static CatchClause catchClause3(TypeName exceptionType, List<Statement> statem ents) => catchClause5(exceptionType, null, null, statements);
3304
3305 static CatchClause catchClause4(TypeName exceptionType, String exceptionParame ter, List<Statement> statements) => catchClause5(exceptionType, exceptionParamet er, null, statements);
3306
3307 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));
3308
3309 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));
3310
3311 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));
3312
3313 static CompilationUnit compilationUnit() => compilationUnit8(null, null, null) ;
3314
3315 static CompilationUnit compilationUnit2(List<CompilationUnitMember> declaratio ns) => compilationUnit8(null, null, list(declarations));
3316
3317 static CompilationUnit compilationUnit3(List<Directive> directives) => compila tionUnit8(null, list(directives), null);
3318
3319 static CompilationUnit compilationUnit4(List<Directive> directives, List<Compi lationUnitMember> declarations) => compilationUnit8(null, directives, declaratio ns);
3320
3321 static CompilationUnit compilationUnit5(String scriptTag) => compilationUnit8( scriptTag, null, null);
3322
3323 static CompilationUnit compilationUnit6(String scriptTag, List<CompilationUnit Member> declarations) => compilationUnit8(scriptTag, null, list(declarations));
3324
3325 static CompilationUnit compilationUnit7(String scriptTag, List<Directive> dire ctives) => compilationUnit8(scriptTag, list(directives), null);
3326
3327 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));
3328
3329 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);
3330
3331 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());
3332
3333 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);
3334
3335 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);
3336
3337 static ConstructorName constructorName(TypeName type, String name) => new Cons tructorName(type, name == null ? null : TokenFactory.tokenFromType(TokenType.PER IOD), name == null ? null : identifier3(name));
3338
3339 static ContinueStatement continueStatement([String label]) {
3340 SimpleIdentifier labelNode = label == null ? null : identifier3(label);
3341 return new ContinueStatement(TokenFactory.tokenFromKeyword(Keyword.CONTINUE) , labelNode, TokenFactory.tokenFromType(TokenType.SEMICOLON));
3342 }
3343
3344 static DeclaredIdentifier declaredIdentifier(Keyword keyword, String identifie r) => declaredIdentifier2(keyword, null, identifier);
3345
3346 static DeclaredIdentifier declaredIdentifier2(Keyword keyword, TypeName type, String identifier) => new DeclaredIdentifier(null, null, keyword == null ? null : TokenFactory.tokenFromKeyword(keyword), type, identifier3(identifier));
3347
3348 static DeclaredIdentifier declaredIdentifier3(String identifier) => declaredId entifier2(null, null, identifier);
3349
3350 static DeclaredIdentifier declaredIdentifier4(TypeName type, String identifier ) => declaredIdentifier2(null, type, identifier);
3351
3352 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));
3353
3354 static DoubleLiteral doubleLiteral(double value) => new DoubleLiteral(TokenFac tory.tokenFromString(value.toString()), value);
3355
3356 static EmptyFunctionBody emptyFunctionBody() => new EmptyFunctionBody(TokenFac tory.tokenFromType(TokenType.SEMICOLON));
3357
3358 static EmptyStatement emptyStatement() => new EmptyStatement(TokenFactory.toke nFromType(TokenType.SEMICOLON));
3359
3360 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));
3361
3362 static ExportDirective exportDirective2(String uri, List<Combinator> combinato rs) => exportDirective(new List<Annotation>(), uri, combinators);
3363
3364 static ExpressionFunctionBody expressionFunctionBody(Expression expression) => new ExpressionFunctionBody(TokenFactory.tokenFromType(TokenType.FUNCTION), expr ession, TokenFactory.tokenFromType(TokenType.SEMICOLON));
3365
3366 static ExpressionStatement expressionStatement(Expression expression) => new E xpressionStatement(expression, TokenFactory.tokenFromType(TokenType.SEMICOLON));
3367
3368 static ExtendsClause extendsClause(TypeName type) => new ExtendsClause(TokenFa ctory.tokenFromKeyword(Keyword.EXTENDS), type);
3369
3370 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));
3371
3372 static FieldDeclaration fieldDeclaration2(bool isStatic, Keyword keyword, List <VariableDeclaration> variables) => fieldDeclaration(isStatic, keyword, null, va riables);
3373
3374 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);
3375
3376 static FieldFormalParameter fieldFormalParameter2(String identifier) => fieldF ormalParameter(null, null, identifier);
3377
3378 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);
3379
3380 static FormalParameterList formalParameterList(List<FormalParameter> parameter s) => new FormalParameterList(TokenFactory.tokenFromType(TokenType.OPEN_PAREN), list(parameters), null, null, TokenFactory.tokenFromType(TokenType.CLOSE_PAREN)) ;
3381
3382 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);
3383
3384 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);
3385
3386 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);
3387
3388 static FunctionDeclarationStatement functionDeclarationStatement(TypeName type , Keyword keyword, String name, FunctionExpression functionExpression) => new Fu nctionDeclarationStatement(functionDeclaration(type, keyword, name, functionExpr ession));
3389
3390 static FunctionExpression functionExpression() => new FunctionExpression(forma lParameterList([]), blockFunctionBody2([]));
3391
3392 static FunctionExpression functionExpression2(FormalParameterList parameters, FunctionBody body) => new FunctionExpression(parameters, body);
3393
3394 static FunctionExpressionInvocation functionExpressionInvocation(Expression fu nction, List<Expression> arguments) => new FunctionExpressionInvocation(function , argumentList(arguments));
3395
3396 static FunctionTypedFormalParameter functionTypedFormalParameter(TypeName retu rnType, String identifier, List<FormalParameter> parameters) => new FunctionType dFormalParameter(null, null, returnType, identifier3(identifier), formalParamete rList(parameters));
3397
3398 static HideCombinator hideCombinator(List<SimpleIdentifier> identifiers) => ne w HideCombinator(TokenFactory.tokenFromString("hide"), list(identifiers));
3399
3400 static HideCombinator hideCombinator2(List<String> identifiers) {
3401 List<SimpleIdentifier> identifierList = new List<SimpleIdentifier>();
3402 for (String identifier in identifiers) {
3403 identifierList.add(identifier3(identifier));
3404 }
3405 return new HideCombinator(TokenFactory.tokenFromString("hide"), identifierLi st);
3406 }
3407
3408 static PrefixedIdentifier identifier(SimpleIdentifier prefix, SimpleIdentifier identifier) => new PrefixedIdentifier(prefix, TokenFactory.tokenFromType(TokenT ype.PERIOD), identifier);
3409
3410 static SimpleIdentifier identifier3(String lexeme) => new SimpleIdentifier(Tok enFactory.tokenFromTypeAndString(TokenType.IDENTIFIER, lexeme));
3411
3412 static PrefixedIdentifier identifier4(String prefix, SimpleIdentifier identifi er) => new PrefixedIdentifier(identifier3(prefix), TokenFactory.tokenFromType(To kenType.PERIOD), identifier);
3413
3414 static PrefixedIdentifier identifier5(String prefix, String identifier) => new PrefixedIdentifier(identifier3(prefix), TokenFactory.tokenFromType(TokenType.PE RIOD), identifier3(identifier));
3415
3416 static IfStatement ifStatement(Expression condition, Statement thenStatement) => ifStatement2(condition, thenStatement, null);
3417
3418 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);
3419
3420 static ImplementsClause implementsClause(List<TypeName> types) => new Implemen tsClause(TokenFactory.tokenFromKeyword(Keyword.IMPLEMENTS), list(types));
3421
3422 static ImportDirective importDirective(List<Annotation> metadata, String uri, String prefix, List<Combinator> combinators) => new ImportDirective(null, metada ta, TokenFactory.tokenFromKeyword(Keyword.IMPORT), string2(uri), null, prefix == null ? null : TokenFactory.tokenFromKeyword(Keyword.AS), prefix == null ? null : identifier3(prefix), list(combinators), TokenFactory.tokenFromType(TokenType.S EMICOLON));
3423
3424 static ImportDirective importDirective2(String uri, String prefix, List<Combin ator> combinators) => importDirective(new List<Annotation>(), uri, prefix, combi nators);
3425
3426 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 ));
3427
3428 static InstanceCreationExpression instanceCreationExpression(Keyword keyword, ConstructorName name, List<Expression> arguments) => new InstanceCreationExpress ion(keyword == null ? null : TokenFactory.tokenFromKeyword(keyword), name, argum entList(arguments));
3429
3430 static InstanceCreationExpression instanceCreationExpression2(Keyword keyword, TypeName type, List<Expression> arguments) => instanceCreationExpression3(keywo rd, type, null, arguments);
3431
3432 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);
3433
3434 static IntegerLiteral integer(int value) => new IntegerLiteral(TokenFactory.to kenFromTypeAndString(TokenType.INT, value.toString()), value);
3435
3436 static InterpolationExpression interpolationExpression(Expression expression) => new InterpolationExpression(TokenFactory.tokenFromType(TokenType.STRING_INTER POLATION_EXPRESSION), expression, TokenFactory.tokenFromType(TokenType.CLOSE_CUR LY_BRACKET));
3437
3438 static InterpolationExpression interpolationExpression2(String identifier) => new InterpolationExpression(TokenFactory.tokenFromType(TokenType.STRING_INTERPOL ATION_IDENTIFIER), identifier3(identifier), null);
3439
3440 static InterpolationString interpolationString(String contents, String value) => new InterpolationString(TokenFactory.tokenFromString(contents), value);
3441
3442 static IsExpression isExpression(Expression expression, bool negated, TypeName type) => new IsExpression(expression, TokenFactory.tokenFromKeyword(Keyword.IS) , negated ? TokenFactory.tokenFromType(TokenType.BANG) : null, type);
3443
3444 static Label label(SimpleIdentifier label) => new Label(label, TokenFactory.to kenFromType(TokenType.COLON));
3445
3446 static Label label2(String label) => AstFactory.label(identifier3(label));
3447
3448 static LabeledStatement labeledStatement(List<Label> labels, Statement stateme nt) => new LabeledStatement(labels, statement);
3449
3450 static LibraryDirective libraryDirective(List<Annotation> metadata, LibraryIde ntifier libraryName) => new LibraryDirective(null, metadata, TokenFactory.tokenF romKeyword(Keyword.LIBRARY), libraryName, TokenFactory.tokenFromType(TokenType.S EMICOLON));
3451
3452 static LibraryDirective libraryDirective2(String libraryName) => libraryDirect ive(new List<Annotation>(), libraryIdentifier2([libraryName]));
3453
3454 static LibraryIdentifier libraryIdentifier(List<SimpleIdentifier> components) => new LibraryIdentifier(list(components));
3455
3456 static LibraryIdentifier libraryIdentifier2(List<String> components) {
3457 List<SimpleIdentifier> componentList = new List<SimpleIdentifier>();
3458 for (String component in components) {
3459 componentList.add(identifier3(component));
3460 }
3461 return new LibraryIdentifier(componentList);
3462 }
3463
3464 static List list(List<Object> elements) {
3465 List elementList = new List();
3466 for (Object element in elements) {
3467 elementList.add(element);
3468 }
3469 return elementList;
3470 }
3471
3472 static ListLiteral listLiteral(List<Expression> elements) => listLiteral2(null , null, elements);
3473
3474 static ListLiteral listLiteral2(Keyword keyword, TypeArgumentList typeArgument s, List<Expression> elements) => new ListLiteral(keyword == null ? null : TokenF actory.tokenFromKeyword(keyword), null, TokenFactory.tokenFromType(TokenType.OPE N_SQUARE_BRACKET), list(elements), TokenFactory.tokenFromType(TokenType.CLOSE_SQ UARE_BRACKET));
3475
3476 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));
3477
3478 static MapLiteral mapLiteral2(List<MapLiteralEntry> entries) => mapLiteral(nul l, null, entries);
3479
3480 static MapLiteralEntry mapLiteralEntry(String key, Expression value) => new Ma pLiteralEntry(string2(key), TokenFactory.tokenFromType(TokenType.COLON), value);
3481
3482 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());
3483
3484 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);
3485
3486 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));
3487
3488 static MethodInvocation methodInvocation2(String methodName, List<Expression> arguments) => methodInvocation(null, methodName, arguments);
3489
3490 static NamedExpression namedExpression(Label label, Expression expression) => new NamedExpression(label, expression);
3491
3492 static NamedExpression namedExpression2(String label, Expression expression) = > namedExpression(label2(label), expression);
3493
3494 static DefaultFormalParameter namedFormalParameter(NormalFormalParameter param eter, Expression expression) => new DefaultFormalParameter(parameter, ParameterK ind.NAMED, expression == null ? null : TokenFactory.tokenFromType(TokenType.COLO N), expression);
3495
3496 static NativeClause nativeClause(String nativeCode) => new NativeClause(TokenF actory.tokenFromString("native"), string2(nativeCode));
3497
3498 static NativeFunctionBody nativeFunctionBody(String nativeMethodName) => new N ativeFunctionBody(TokenFactory.tokenFromString("native"), string2(nativeMethodNa me), TokenFactory.tokenFromType(TokenType.SEMICOLON));
3499
3500 static NullLiteral nullLiteral() => new NullLiteral(TokenFactory.tokenFromKeyw ord(Keyword.NULL));
3501
3502 static ParenthesizedExpression parenthesizedExpression(Expression expression) => new ParenthesizedExpression(TokenFactory.tokenFromType(TokenType.OPEN_PAREN), expression, TokenFactory.tokenFromType(TokenType.CLOSE_PAREN));
3503
3504 static PartDirective partDirective(List<Annotation> metadata, String url) => n ew PartDirective(null, metadata, TokenFactory.tokenFromKeyword(Keyword.PART), st ring2(url), TokenFactory.tokenFromType(TokenType.SEMICOLON));
3505
3506 static PartDirective partDirective2(String url) => partDirective(new List<Anno tation>(), url);
3507
3508 static PartOfDirective partOfDirective(LibraryIdentifier libraryName) => partO fDirective2(new List<Annotation>(), libraryName);
3509
3510 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));
3511
3512 static DefaultFormalParameter positionalFormalParameter(NormalFormalParameter parameter, Expression expression) => new DefaultFormalParameter(parameter, Param eterKind.POSITIONAL, expression == null ? null : TokenFactory.tokenFromType(Toke nType.EQ), expression);
3513
3514 static PostfixExpression postfixExpression(Expression expression, TokenType op erator) => new PostfixExpression(expression, TokenFactory.tokenFromType(operator ));
3515
3516 static PrefixExpression prefixExpression(TokenType operator, Expression expres sion) => new PrefixExpression(TokenFactory.tokenFromType(operator), expression);
3517
3518 static PropertyAccess propertyAccess(Expression target, SimpleIdentifier prope rtyName) => new PropertyAccess(target, TokenFactory.tokenFromType(TokenType.PERI OD), propertyName);
3519
3520 static PropertyAccess propertyAccess2(Expression target, String propertyName) => new PropertyAccess(target, TokenFactory.tokenFromType(TokenType.PERIOD), iden tifier3(propertyName));
3521
3522 static RedirectingConstructorInvocation redirectingConstructorInvocation(List< Expression> arguments) => redirectingConstructorInvocation2(null, arguments);
3523
3524 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));
3525
3526 static RethrowExpression rethrowExpression() => new RethrowExpression(TokenFac tory.tokenFromKeyword(Keyword.RETHROW));
3527
3528 static ReturnStatement returnStatement() => returnStatement2(null);
3529
3530 static ReturnStatement returnStatement2(Expression expression) => new ReturnSt atement(TokenFactory.tokenFromKeyword(Keyword.RETURN), expression, TokenFactory. tokenFromType(TokenType.SEMICOLON));
3531
3532 static ScriptTag scriptTag(String scriptTag) => new ScriptTag(TokenFactory.tok enFromString(scriptTag));
3533
3534 static ShowCombinator showCombinator(List<SimpleIdentifier> identifiers) => ne w ShowCombinator(TokenFactory.tokenFromString("show"), list(identifiers));
3535
3536 static ShowCombinator showCombinator2(List<String> identifiers) {
3537 List<SimpleIdentifier> identifierList = new List<SimpleIdentifier>();
3538 for (String identifier in identifiers) {
3539 identifierList.add(identifier3(identifier));
3540 }
3541 return new ShowCombinator(TokenFactory.tokenFromString("show"), identifierLi st);
3542 }
3543
3544 static SimpleFormalParameter simpleFormalParameter(Keyword keyword, String par ameterName) => simpleFormalParameter2(keyword, null, parameterName);
3545
3546 static SimpleFormalParameter simpleFormalParameter2(Keyword keyword, TypeName type, String parameterName) => new SimpleFormalParameter(null, null, keyword == null ? null : TokenFactory.tokenFromKeyword(keyword), type, identifier3(paramete rName));
3547
3548 static SimpleFormalParameter simpleFormalParameter3(String parameterName) => s impleFormalParameter2(null, null, parameterName);
3549
3550 static SimpleFormalParameter simpleFormalParameter4(TypeName type, String para meterName) => simpleFormalParameter2(null, type, parameterName);
3551
3552 static StringInterpolation string(List<InterpolationElement> elements) => new StringInterpolation(list(elements));
3553
3554 static SimpleStringLiteral string2(String content) => new SimpleStringLiteral( TokenFactory.tokenFromString("'${content}'"), content);
3555
3556 static SuperConstructorInvocation superConstructorInvocation(List<Expression> arguments) => superConstructorInvocation2(null, arguments);
3557
3558 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));
3559
3560 static SuperExpression superExpression() => new SuperExpression(TokenFactory.t okenFromKeyword(Keyword.SUPER));
3561
3562 static SwitchCase switchCase(Expression expression, List<Statement> statements ) => switchCase2(new List<Label>(), expression, statements);
3563
3564 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));
3565
3566 static SwitchDefault switchDefault(List<Label> labels, List<Statement> stateme nts) => new SwitchDefault(labels, TokenFactory.tokenFromKeyword(Keyword.DEFAULT) , TokenFactory.tokenFromType(TokenType.COLON), list(statements));
3567
3568 static SwitchDefault switchDefault2(List<Statement> statements) => switchDefau lt(new List<Label>(), statements);
3569
3570 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));
3571
3572 static SymbolLiteral symbolLiteral(List<String> components) {
3573 List<Token> identifierList = new List<Token>();
3574 for (String component in components) {
3575 identifierList.add(TokenFactory.tokenFromTypeAndString(TokenType.IDENTIFIE R, component));
3576 }
3577 return new SymbolLiteral(TokenFactory.tokenFromType(TokenType.HASH), new Lis t.from(identifierList));
3578 }
3579
3580 static ThisExpression thisExpression() => new ThisExpression(TokenFactory.toke nFromKeyword(Keyword.THIS));
3581
3582 static ThrowExpression throwExpression() => throwExpression2(null);
3583
3584 static ThrowExpression throwExpression2(Expression expression) => new ThrowExp ression(TokenFactory.tokenFromKeyword(Keyword.THROW), expression);
3585
3586 static TopLevelVariableDeclaration topLevelVariableDeclaration(Keyword keyword , TypeName type, List<VariableDeclaration> variables) => new TopLevelVariableDec laration(null, null, variableDeclarationList(keyword, type, variables), TokenFac tory.tokenFromType(TokenType.SEMICOLON));
3587
3588 static TopLevelVariableDeclaration topLevelVariableDeclaration2(Keyword keywor d, List<VariableDeclaration> variables) => new TopLevelVariableDeclaration(null, null, variableDeclarationList(keyword, null, variables), TokenFactory.tokenFrom Type(TokenType.SEMICOLON));
3589
3590 static TryStatement tryStatement(Block body, Block finallyClause) => tryStatem ent3(body, new List<CatchClause>(), finallyClause);
3591
3592 static TryStatement tryStatement2(Block body, List<CatchClause> catchClauses) => tryStatement3(body, list(catchClauses), null);
3593
3594 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);
3595
3596 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));
3597
3598 static TypeArgumentList typeArgumentList(List<TypeName> typeNames) => new Type ArgumentList(TokenFactory.tokenFromType(TokenType.LT), list(typeNames), TokenFac tory.tokenFromType(TokenType.GT));
3599
3600 /**
3601 * Create a type name whose name has been resolved to the given element and wh ose type has been
3602 * resolved to the type of the given element.
3603 *
3604 * <b>Note:</b> This method does not correctly handle class elements that have type parameters.
3605 *
3606 * @param element the element defining the type represented by the type name
3607 * @return the type name that was created
3608 */
3609 static TypeName typeName(ClassElement element, List<TypeName> arguments) {
3610 SimpleIdentifier name = identifier3(element.name);
3611 name.staticElement = element;
3612 TypeName typeName = typeName3(name, arguments);
3613 typeName.type = element.type;
3614 return typeName;
3615 }
3616
3617 static TypeName typeName3(Identifier name, List<TypeName> arguments) {
3618 if (arguments.length == 0) {
3619 return new TypeName(name, null);
3620 }
3621 return new TypeName(name, typeArgumentList(arguments));
3622 }
3623
3624 static TypeName typeName4(String name, List<TypeName> arguments) {
3625 if (arguments.length == 0) {
3626 return new TypeName(identifier3(name), null);
3627 }
3628 return new TypeName(identifier3(name), typeArgumentList(arguments));
3629 }
3630
3631 static TypeParameter typeParameter(String name) => new TypeParameter(null, nul l, identifier3(name), null, null);
3632
3633 static TypeParameter typeParameter2(String name, TypeName bound) => new TypePa rameter(null, null, identifier3(name), TokenFactory.tokenFromKeyword(Keyword.EXT ENDS), bound);
3634
3635 static TypeParameterList typeParameterList(List<String> typeNames) {
3636 List<TypeParameter> typeParameters = new List<TypeParameter>();
3637 for (String typeName in typeNames) {
3638 typeParameters.add(typeParameter(typeName));
3639 }
3640 return new TypeParameterList(TokenFactory.tokenFromType(TokenType.LT), typeP arameters, TokenFactory.tokenFromType(TokenType.GT));
3641 }
3642
3643 static VariableDeclaration variableDeclaration(String name) => new VariableDec laration(null, null, identifier3(name), null, null);
3644
3645 static VariableDeclaration variableDeclaration2(String name, Expression initia lizer) => new VariableDeclaration(null, null, identifier3(name), TokenFactory.to kenFromType(TokenType.EQ), initializer);
3646
3647 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));
3648
3649 static VariableDeclarationList variableDeclarationList2(Keyword keyword, List< VariableDeclaration> variables) => variableDeclarationList(keyword, null, variab les);
3650
3651 static VariableDeclarationStatement variableDeclarationStatement(Keyword keywo rd, TypeName type, List<VariableDeclaration> variables) => new VariableDeclarati onStatement(variableDeclarationList(keyword, type, variables), TokenFactory.toke nFromType(TokenType.SEMICOLON));
3652
3653 static VariableDeclarationStatement variableDeclarationStatement2(Keyword keyw ord, List<VariableDeclaration> variables) => variableDeclarationStatement(keywor d, null, variables);
3654
3655 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);
3656
3657 static WithClause withClause(List<TypeName> types) => new WithClause(TokenFact ory.tokenFromKeyword(Keyword.WITH), list(types));
3658 }
3659
3660 class NodeListTest extends EngineTestCase {
3661 void test_add() {
3662 AstNode parent = AstFactory.argumentList([]);
3663 AstNode firstNode = AstFactory.booleanLiteral(true);
3664 AstNode secondNode = AstFactory.booleanLiteral(false);
3665 NodeList<AstNode> list = new NodeList<AstNode>(parent);
3666 list.insert(0, secondNode);
3667 list.insert(0, firstNode);
3668 EngineTestCase.assertSizeOfList(2, list);
3669 JUnitTestCase.assertSame(firstNode, list[0]);
3670 JUnitTestCase.assertSame(secondNode, list[1]);
3671 JUnitTestCase.assertSame(parent, firstNode.parent);
3672 JUnitTestCase.assertSame(parent, secondNode.parent);
3673 AstNode thirdNode = AstFactory.booleanLiteral(false);
3674 list.insert(1, thirdNode);
3675 EngineTestCase.assertSizeOfList(3, list);
3676 JUnitTestCase.assertSame(firstNode, list[0]);
3677 JUnitTestCase.assertSame(thirdNode, list[1]);
3678 JUnitTestCase.assertSame(secondNode, list[2]);
3679 JUnitTestCase.assertSame(parent, firstNode.parent);
3680 JUnitTestCase.assertSame(parent, secondNode.parent);
3681 JUnitTestCase.assertSame(parent, thirdNode.parent);
3682 }
3683
3684 void test_add_negative() {
3685 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
3686 try {
3687 list.insert(-1, AstFactory.booleanLiteral(true));
3688 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
3689 } on RangeError catch (exception) {
3690 }
3691 }
3692
3693 void test_add_tooBig() {
3694 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
3695 try {
3696 list.insert(1, AstFactory.booleanLiteral(true));
3697 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
3698 } on RangeError catch (exception) {
3699 }
3700 }
3701
3702 void test_addAll() {
3703 AstNode parent = AstFactory.argumentList([]);
3704 List<AstNode> firstNodes = new List<AstNode>();
3705 AstNode firstNode = AstFactory.booleanLiteral(true);
3706 AstNode secondNode = AstFactory.booleanLiteral(false);
3707 firstNodes.add(firstNode);
3708 firstNodes.add(secondNode);
3709 NodeList<AstNode> list = new NodeList<AstNode>(parent);
3710 list.addAll(firstNodes);
3711 EngineTestCase.assertSizeOfList(2, list);
3712 JUnitTestCase.assertSame(firstNode, list[0]);
3713 JUnitTestCase.assertSame(secondNode, list[1]);
3714 JUnitTestCase.assertSame(parent, firstNode.parent);
3715 JUnitTestCase.assertSame(parent, secondNode.parent);
3716 List<AstNode> secondNodes = new List<AstNode>();
3717 AstNode thirdNode = AstFactory.booleanLiteral(true);
3718 AstNode fourthNode = AstFactory.booleanLiteral(false);
3719 secondNodes.add(thirdNode);
3720 secondNodes.add(fourthNode);
3721 list.addAll(secondNodes);
3722 EngineTestCase.assertSizeOfList(4, list);
3723 JUnitTestCase.assertSame(firstNode, list[0]);
3724 JUnitTestCase.assertSame(secondNode, list[1]);
3725 JUnitTestCase.assertSame(thirdNode, list[2]);
3726 JUnitTestCase.assertSame(fourthNode, list[3]);
3727 JUnitTestCase.assertSame(parent, firstNode.parent);
3728 JUnitTestCase.assertSame(parent, secondNode.parent);
3729 JUnitTestCase.assertSame(parent, thirdNode.parent);
3730 JUnitTestCase.assertSame(parent, fourthNode.parent);
3731 }
3732
3733 void test_create() {
3734 AstNode owner = AstFactory.argumentList([]);
3735 NodeList<AstNode> list = NodeList.create(owner);
3736 JUnitTestCase.assertNotNull(list);
3737 EngineTestCase.assertSizeOfList(0, list);
3738 JUnitTestCase.assertSame(owner, list.owner);
3739 }
3740
3741 void test_creation() {
3742 AstNode owner = AstFactory.argumentList([]);
3743 NodeList<AstNode> list = new NodeList<AstNode>(owner);
3744 JUnitTestCase.assertNotNull(list);
3745 EngineTestCase.assertSizeOfList(0, list);
3746 JUnitTestCase.assertSame(owner, list.owner);
3747 }
3748
3749 void test_get_negative() {
3750 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
3751 try {
3752 list[-1];
3753 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
3754 } on RangeError catch (exception) {
3755 }
3756 }
3757
3758 void test_get_tooBig() {
3759 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
3760 try {
3761 list[1];
3762 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
3763 } on RangeError catch (exception) {
3764 }
3765 }
3766
3767 void test_getBeginToken_empty() {
3768 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
3769 JUnitTestCase.assertNull(list.beginToken);
3770 }
3771
3772 void test_getBeginToken_nonEmpty() {
3773 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
3774 AstNode node = AstFactory.parenthesizedExpression(AstFactory.booleanLiteral( true));
3775 list.add(node);
3776 JUnitTestCase.assertSame(node.beginToken, list.beginToken);
3777 }
3778
3779 void test_getEndToken_empty() {
3780 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
3781 JUnitTestCase.assertNull(list.endToken);
3782 }
3783
3784 void test_getEndToken_nonEmpty() {
3785 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
3786 AstNode node = AstFactory.parenthesizedExpression(AstFactory.booleanLiteral( true));
3787 list.add(node);
3788 JUnitTestCase.assertSame(node.endToken, list.endToken);
3789 }
3790
3791 void test_indexOf() {
3792 List<AstNode> nodes = new List<AstNode>();
3793 AstNode firstNode = AstFactory.booleanLiteral(true);
3794 AstNode secondNode = AstFactory.booleanLiteral(false);
3795 AstNode thirdNode = AstFactory.booleanLiteral(true);
3796 AstNode fourthNode = AstFactory.booleanLiteral(false);
3797 nodes.add(firstNode);
3798 nodes.add(secondNode);
3799 nodes.add(thirdNode);
3800 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
3801 list.addAll(nodes);
3802 EngineTestCase.assertSizeOfList(3, list);
3803 JUnitTestCase.assertEquals(0, list.indexOf(firstNode));
3804 JUnitTestCase.assertEquals(1, list.indexOf(secondNode));
3805 JUnitTestCase.assertEquals(2, list.indexOf(thirdNode));
3806 JUnitTestCase.assertEquals(-1, list.indexOf(fourthNode));
3807 JUnitTestCase.assertEquals(-1, list.indexOf(null));
3808 }
3809
3810 void test_remove() {
3811 List<AstNode> nodes = new List<AstNode>();
3812 AstNode firstNode = AstFactory.booleanLiteral(true);
3813 AstNode secondNode = AstFactory.booleanLiteral(false);
3814 AstNode thirdNode = AstFactory.booleanLiteral(true);
3815 nodes.add(firstNode);
3816 nodes.add(secondNode);
3817 nodes.add(thirdNode);
3818 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
3819 list.addAll(nodes);
3820 EngineTestCase.assertSizeOfList(3, list);
3821 JUnitTestCase.assertSame(secondNode, list.removeAt(1));
3822 EngineTestCase.assertSizeOfList(2, list);
3823 JUnitTestCase.assertSame(firstNode, list[0]);
3824 JUnitTestCase.assertSame(thirdNode, list[1]);
3825 }
3826
3827 void test_remove_negative() {
3828 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
3829 try {
3830 list.removeAt(-1);
3831 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
3832 } on RangeError catch (exception) {
3833 }
3834 }
3835
3836 void test_remove_tooBig() {
3837 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
3838 try {
3839 list.removeAt(1);
3840 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
3841 } on RangeError catch (exception) {
3842 }
3843 }
3844
3845 void test_set() {
3846 List<AstNode> nodes = new List<AstNode>();
3847 AstNode firstNode = AstFactory.booleanLiteral(true);
3848 AstNode secondNode = AstFactory.booleanLiteral(false);
3849 AstNode thirdNode = AstFactory.booleanLiteral(true);
3850 nodes.add(firstNode);
3851 nodes.add(secondNode);
3852 nodes.add(thirdNode);
3853 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
3854 list.addAll(nodes);
3855 EngineTestCase.assertSizeOfList(3, list);
3856 AstNode fourthNode = AstFactory.integer(0);
3857 JUnitTestCase.assertSame(secondNode, javaListSet(list, 1, fourthNode));
3858 EngineTestCase.assertSizeOfList(3, list);
3859 JUnitTestCase.assertSame(firstNode, list[0]);
3860 JUnitTestCase.assertSame(fourthNode, list[1]);
3861 JUnitTestCase.assertSame(thirdNode, list[2]);
3862 }
3863
3864 void test_set_negative() {
3865 AstNode node = AstFactory.booleanLiteral(true);
3866 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
3867 try {
3868 javaListSet(list, -1, node);
3869 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
3870 } on RangeError catch (exception) {
3871 }
3872 }
3873
3874 void test_set_tooBig() {
3875 AstNode node = AstFactory.booleanLiteral(true);
3876 NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList([]));
3877 try {
3878 javaListSet(list, 1, node);
3879 JUnitTestCase.fail("Expected IndexOutOfBoundsException");
3880 } on RangeError catch (exception) {
3881 }
3882 }
3883
3884 static dartSuite() {
3885 _ut.group('NodeListTest', () {
3886 _ut.test('test_add', () {
3887 final __test = new NodeListTest();
3888 runJUnitTest(__test, __test.test_add);
3889 });
3890 _ut.test('test_addAll', () {
3891 final __test = new NodeListTest();
3892 runJUnitTest(__test, __test.test_addAll);
3893 });
3894 _ut.test('test_add_negative', () {
3895 final __test = new NodeListTest();
3896 runJUnitTest(__test, __test.test_add_negative);
3897 });
3898 _ut.test('test_add_tooBig', () {
3899 final __test = new NodeListTest();
3900 runJUnitTest(__test, __test.test_add_tooBig);
3901 });
3902 _ut.test('test_create', () {
3903 final __test = new NodeListTest();
3904 runJUnitTest(__test, __test.test_create);
3905 });
3906 _ut.test('test_creation', () {
3907 final __test = new NodeListTest();
3908 runJUnitTest(__test, __test.test_creation);
3909 });
3910 _ut.test('test_getBeginToken_empty', () {
3911 final __test = new NodeListTest();
3912 runJUnitTest(__test, __test.test_getBeginToken_empty);
3913 });
3914 _ut.test('test_getBeginToken_nonEmpty', () {
3915 final __test = new NodeListTest();
3916 runJUnitTest(__test, __test.test_getBeginToken_nonEmpty);
3917 });
3918 _ut.test('test_getEndToken_empty', () {
3919 final __test = new NodeListTest();
3920 runJUnitTest(__test, __test.test_getEndToken_empty);
3921 });
3922 _ut.test('test_getEndToken_nonEmpty', () {
3923 final __test = new NodeListTest();
3924 runJUnitTest(__test, __test.test_getEndToken_nonEmpty);
3925 });
3926 _ut.test('test_get_negative', () {
3927 final __test = new NodeListTest();
3928 runJUnitTest(__test, __test.test_get_negative);
3929 });
3930 _ut.test('test_get_tooBig', () {
3931 final __test = new NodeListTest();
3932 runJUnitTest(__test, __test.test_get_tooBig);
3933 });
3934 _ut.test('test_indexOf', () {
3935 final __test = new NodeListTest();
3936 runJUnitTest(__test, __test.test_indexOf);
3937 });
3938 _ut.test('test_remove', () {
3939 final __test = new NodeListTest();
3940 runJUnitTest(__test, __test.test_remove);
3941 });
3942 _ut.test('test_remove_negative', () {
3943 final __test = new NodeListTest();
3944 runJUnitTest(__test, __test.test_remove_negative);
3945 });
3946 _ut.test('test_remove_tooBig', () {
3947 final __test = new NodeListTest();
3948 runJUnitTest(__test, __test.test_remove_tooBig);
3949 });
3950 _ut.test('test_set', () {
3951 final __test = new NodeListTest();
3952 runJUnitTest(__test, __test.test_set);
3953 });
3954 _ut.test('test_set_negative', () {
3955 final __test = new NodeListTest();
3956 runJUnitTest(__test, __test.test_set_negative);
3957 });
3958 _ut.test('test_set_tooBig', () {
3959 final __test = new NodeListTest();
3960 runJUnitTest(__test, __test.test_set_tooBig);
3961 });
3962 });
3963 }
3964 }
3965
3966 class BreadthFirstVisitorTest extends ParserTestCase {
3967 void testIt() {
3968 String source = EngineTestCase.createSource([
3969 "class A {",
3970 " bool get g => true;",
3971 "}",
3972 "class B {",
3973 " int f() {",
3974 " num q() {",
3975 " return 3;",
3976 " }",
3977 " return q() + 4;",
3978 " }",
3979 "}",
3980 "A f(var p) {",
3981 " if ((p as A).g) {",
3982 " return p;",
3983 " } else {",
3984 " return null;",
3985 " }",
3986 "}"]);
3987 CompilationUnit unit = ParserTestCase.parseCompilationUnit(source, []);
3988 List<AstNode> nodes = new List<AstNode>();
3989 BreadthFirstVisitor<Object> visitor = new BreadthFirstVisitor_BreadthFirstVi sitorTest_testIt(nodes);
3990 visitor.visitAllNodes(unit);
3991 EngineTestCase.assertSizeOfList(59, nodes);
3992 EngineTestCase.assertInstanceOf((obj) => obj is CompilationUnit, Compilation Unit, nodes[0]);
3993 EngineTestCase.assertInstanceOf((obj) => obj is ClassDeclaration, ClassDecla ration, nodes[2]);
3994 EngineTestCase.assertInstanceOf((obj) => obj is FunctionDeclaration, Functio nDeclaration, nodes[3]);
3995 EngineTestCase.assertInstanceOf((obj) => obj is FunctionDeclarationStatement , FunctionDeclarationStatement, nodes[27]);
3996 EngineTestCase.assertInstanceOf((obj) => obj is IntegerLiteral, IntegerLiter al, nodes[58]);
3997 }
3998
3999 static dartSuite() {
4000 _ut.group('BreadthFirstVisitorTest', () {
4001 _ut.test('testIt', () {
4002 final __test = new BreadthFirstVisitorTest();
4003 runJUnitTest(__test, __test.testIt);
4004 });
4005 });
4006 }
4007 }
4008
4009 class BreadthFirstVisitor_BreadthFirstVisitorTest_testIt extends BreadthFirstVis itor<Object> {
4010 List<AstNode> nodes;
4011
4012 BreadthFirstVisitor_BreadthFirstVisitorTest_testIt(this.nodes) : super();
4013
4014 @override
4015 Object visitNode(AstNode node) {
4016 nodes.add(node);
4017 return super.visitNode(node);
4018 }
4019 }
4020
4021 class IndexExpressionTest extends EngineTestCase {
4022 void test_inGetterContext_assignment_compound_left() {
4023 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
4024 // a[i] += ?
4025 AstFactory.assignmentExpression(expression, TokenType.PLUS_EQ, null);
4026 JUnitTestCase.assertTrue(expression.inGetterContext());
4027 }
4028
4029 void test_inGetterContext_assignment_simple_left() {
4030 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
4031 // a[i] = ?
4032 AstFactory.assignmentExpression(expression, TokenType.EQ, null);
4033 JUnitTestCase.assertFalse(expression.inGetterContext());
4034 }
4035
4036 void test_inGetterContext_nonAssignment() {
4037 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
4038 // a[i] + ?
4039 AstFactory.binaryExpression(expression, TokenType.PLUS, null);
4040 JUnitTestCase.assertTrue(expression.inGetterContext());
4041 }
4042
4043 void test_inSetterContext_assignment_compound_left() {
4044 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
4045 // a[i] += ?
4046 AstFactory.assignmentExpression(expression, TokenType.PLUS_EQ, null);
4047 JUnitTestCase.assertTrue(expression.inSetterContext());
4048 }
4049
4050 void test_inSetterContext_assignment_compound_right() {
4051 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
4052 // ? += a[i]
4053 AstFactory.assignmentExpression(null, TokenType.PLUS_EQ, expression);
4054 JUnitTestCase.assertFalse(expression.inSetterContext());
4055 }
4056
4057 void test_inSetterContext_assignment_simple_left() {
4058 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
4059 // a[i] = ?
4060 AstFactory.assignmentExpression(expression, TokenType.EQ, null);
4061 JUnitTestCase.assertTrue(expression.inSetterContext());
4062 }
4063
4064 void test_inSetterContext_assignment_simple_right() {
4065 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
4066 // ? = a[i]
4067 AstFactory.assignmentExpression(null, TokenType.EQ, expression);
4068 JUnitTestCase.assertFalse(expression.inSetterContext());
4069 }
4070
4071 void test_inSetterContext_nonAssignment() {
4072 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
4073 AstFactory.binaryExpression(expression, TokenType.PLUS, null);
4074 // a[i] + ?
4075 JUnitTestCase.assertFalse(expression.inSetterContext());
4076 }
4077
4078 void test_inSetterContext_postfix() {
4079 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
4080 AstFactory.postfixExpression(expression, TokenType.PLUS_PLUS);
4081 // a[i]++
4082 JUnitTestCase.assertTrue(expression.inSetterContext());
4083 }
4084
4085 void test_inSetterContext_prefix_bang() {
4086 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
4087 // !a[i]
4088 AstFactory.prefixExpression(TokenType.BANG, expression);
4089 JUnitTestCase.assertFalse(expression.inSetterContext());
4090 }
4091
4092 void test_inSetterContext_prefix_minusMinus() {
4093 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
4094 // --a[i]
4095 AstFactory.prefixExpression(TokenType.MINUS_MINUS, expression);
4096 JUnitTestCase.assertTrue(expression.inSetterContext());
4097 }
4098
4099 void test_inSetterContext_prefix_plusPlus() {
4100 IndexExpression expression = AstFactory.indexExpression(AstFactory.identifie r3("a"), AstFactory.identifier3("b"));
4101 // ++a[i]
4102 AstFactory.prefixExpression(TokenType.PLUS_PLUS, expression);
4103 JUnitTestCase.assertTrue(expression.inSetterContext());
4104 }
4105
4106 static dartSuite() {
4107 _ut.group('IndexExpressionTest', () {
4108 _ut.test('test_inGetterContext_assignment_compound_left', () {
4109 final __test = new IndexExpressionTest();
4110 runJUnitTest(__test, __test.test_inGetterContext_assignment_compound_lef t);
4111 });
4112 _ut.test('test_inGetterContext_assignment_simple_left', () {
4113 final __test = new IndexExpressionTest();
4114 runJUnitTest(__test, __test.test_inGetterContext_assignment_simple_left) ;
4115 });
4116 _ut.test('test_inGetterContext_nonAssignment', () {
4117 final __test = new IndexExpressionTest();
4118 runJUnitTest(__test, __test.test_inGetterContext_nonAssignment);
4119 });
4120 _ut.test('test_inSetterContext_assignment_compound_left', () {
4121 final __test = new IndexExpressionTest();
4122 runJUnitTest(__test, __test.test_inSetterContext_assignment_compound_lef t);
4123 });
4124 _ut.test('test_inSetterContext_assignment_compound_right', () {
4125 final __test = new IndexExpressionTest();
4126 runJUnitTest(__test, __test.test_inSetterContext_assignment_compound_rig ht);
4127 });
4128 _ut.test('test_inSetterContext_assignment_simple_left', () {
4129 final __test = new IndexExpressionTest();
4130 runJUnitTest(__test, __test.test_inSetterContext_assignment_simple_left) ;
4131 });
4132 _ut.test('test_inSetterContext_assignment_simple_right', () {
4133 final __test = new IndexExpressionTest();
4134 runJUnitTest(__test, __test.test_inSetterContext_assignment_simple_right );
4135 });
4136 _ut.test('test_inSetterContext_nonAssignment', () {
4137 final __test = new IndexExpressionTest();
4138 runJUnitTest(__test, __test.test_inSetterContext_nonAssignment);
4139 });
4140 _ut.test('test_inSetterContext_postfix', () {
4141 final __test = new IndexExpressionTest();
4142 runJUnitTest(__test, __test.test_inSetterContext_postfix);
4143 });
4144 _ut.test('test_inSetterContext_prefix_bang', () {
4145 final __test = new IndexExpressionTest();
4146 runJUnitTest(__test, __test.test_inSetterContext_prefix_bang);
4147 });
4148 _ut.test('test_inSetterContext_prefix_minusMinus', () {
4149 final __test = new IndexExpressionTest();
4150 runJUnitTest(__test, __test.test_inSetterContext_prefix_minusMinus);
4151 });
4152 _ut.test('test_inSetterContext_prefix_plusPlus', () {
4153 final __test = new IndexExpressionTest();
4154 runJUnitTest(__test, __test.test_inSetterContext_prefix_plusPlus);
4155 });
4156 });
4157 }
4158 }
4159
4160 class ClassTypeAliasTest extends ParserTestCase {
4161 void test_isAbstract() {
4162 JUnitTestCase.assertFalse(AstFactory.classTypeAlias("A", null, null, null, n ull, null).isAbstract);
4163 JUnitTestCase.assertTrue(AstFactory.classTypeAlias("B", null, Keyword.ABSTRA CT, null, null, null).isAbstract);
4164 }
4165
4166 static dartSuite() {
4167 _ut.group('ClassTypeAliasTest', () {
4168 _ut.test('test_isAbstract', () {
4169 final __test = new ClassTypeAliasTest();
4170 runJUnitTest(__test, __test.test_isAbstract);
4171 });
4172 });
4173 }
4174 }
4175
4176 class ClassDeclarationTest extends ParserTestCase {
4177 void test_getConstructor() {
4178 List<ConstructorInitializer> initializers = new List<ConstructorInitializer> ();
4179 ConstructorDeclaration defaultConstructor = AstFactory.constructorDeclaratio n(AstFactory.identifier3("Test"), null, AstFactory.formalParameterList([]), init ializers);
4180 ConstructorDeclaration aConstructor = AstFactory.constructorDeclaration(AstF actory.identifier3("Test"), "a", AstFactory.formalParameterList([]), initializer s);
4181 ConstructorDeclaration bConstructor = AstFactory.constructorDeclaration(AstF actory.identifier3("Test"), "b", AstFactory.formalParameterList([]), initializer s);
4182 ClassDeclaration clazz = AstFactory.classDeclaration(null, "Test", null, nul l, null, null, [defaultConstructor, aConstructor, bConstructor]);
4183 JUnitTestCase.assertSame(defaultConstructor, clazz.getConstructor(null));
4184 JUnitTestCase.assertSame(aConstructor, clazz.getConstructor("a"));
4185 JUnitTestCase.assertSame(bConstructor, clazz.getConstructor("b"));
4186 JUnitTestCase.assertSame(null, clazz.getConstructor("noSuchConstructor"));
4187 }
4188
4189 void test_getField() {
4190 VariableDeclaration aVar = AstFactory.variableDeclaration("a");
4191 VariableDeclaration bVar = AstFactory.variableDeclaration("b");
4192 VariableDeclaration cVar = AstFactory.variableDeclaration("c");
4193 ClassDeclaration clazz = AstFactory.classDeclaration(null, "Test", null, nul l, null, null, [
4194 AstFactory.fieldDeclaration2(false, null, [aVar]),
4195 AstFactory.fieldDeclaration2(false, null, [bVar, cVar])]);
4196 JUnitTestCase.assertSame(aVar, clazz.getField("a"));
4197 JUnitTestCase.assertSame(bVar, clazz.getField("b"));
4198 JUnitTestCase.assertSame(cVar, clazz.getField("c"));
4199 JUnitTestCase.assertSame(null, clazz.getField("noSuchField"));
4200 }
4201
4202 void test_getMethod() {
4203 MethodDeclaration aMethod = AstFactory.methodDeclaration(null, null, null, n ull, AstFactory.identifier3("a"), AstFactory.formalParameterList([]));
4204 MethodDeclaration bMethod = AstFactory.methodDeclaration(null, null, null, n ull, AstFactory.identifier3("b"), AstFactory.formalParameterList([]));
4205 ClassDeclaration clazz = AstFactory.classDeclaration(null, "Test", null, nul l, null, null, [aMethod, bMethod]);
4206 JUnitTestCase.assertSame(aMethod, clazz.getMethod("a"));
4207 JUnitTestCase.assertSame(bMethod, clazz.getMethod("b"));
4208 JUnitTestCase.assertSame(null, clazz.getMethod("noSuchMethod"));
4209 }
4210
4211 void test_isAbstract() {
4212 JUnitTestCase.assertFalse(AstFactory.classDeclaration(null, "A", null, null, null, null, []).isAbstract);
4213 JUnitTestCase.assertTrue(AstFactory.classDeclaration(Keyword.ABSTRACT, "B", null, null, null, null, []).isAbstract);
4214 }
4215
4216 static dartSuite() {
4217 _ut.group('ClassDeclarationTest', () {
4218 _ut.test('test_getConstructor', () {
4219 final __test = new ClassDeclarationTest();
4220 runJUnitTest(__test, __test.test_getConstructor);
4221 });
4222 _ut.test('test_getField', () {
4223 final __test = new ClassDeclarationTest();
4224 runJUnitTest(__test, __test.test_getField);
4225 });
4226 _ut.test('test_getMethod', () {
4227 final __test = new ClassDeclarationTest();
4228 runJUnitTest(__test, __test.test_getMethod);
4229 });
4230 _ut.test('test_isAbstract', () {
4231 final __test = new ClassDeclarationTest();
4232 runJUnitTest(__test, __test.test_isAbstract);
4233 });
4234 });
4235 }
4236 } 4215 }
4237 4216
4238 class VariableDeclarationTest extends ParserTestCase { 4217 class VariableDeclarationTest extends ParserTestCase {
4239 void test_getDocumentationComment_onGrandParent() { 4218 void test_getDocumentationComment_onGrandParent() {
4240 VariableDeclaration varDecl = AstFactory.variableDeclaration("a"); 4219 VariableDeclaration varDecl = AstFactory.variableDeclaration("a");
4241 TopLevelVariableDeclaration decl = AstFactory.topLevelVariableDeclaration2(K eyword.VAR, [varDecl]); 4220 TopLevelVariableDeclaration decl = AstFactory.topLevelVariableDeclaration2(K eyword.VAR, [varDecl]);
4242 Comment comment = Comment.createDocumentationComment(new List<Token>(0)); 4221 Comment comment = Comment.createDocumentationComment(new List<Token>(0));
4243 JUnitTestCase.assertNull(varDecl.documentationComment); 4222 JUnitTestCase.assertNull(varDecl.documentationComment);
4244 decl.documentationComment = comment; 4223 decl.documentationComment = comment;
4245 JUnitTestCase.assertNotNull(varDecl.documentationComment); 4224 JUnitTestCase.assertNotNull(varDecl.documentationComment);
(...skipping 14 matching lines...) Expand all
4260 runJUnitTest(__test, __test.test_getDocumentationComment_onGrandParent); 4239 runJUnitTest(__test, __test.test_getDocumentationComment_onGrandParent);
4261 }); 4240 });
4262 _ut.test('test_getDocumentationComment_onNode', () { 4241 _ut.test('test_getDocumentationComment_onNode', () {
4263 final __test = new VariableDeclarationTest(); 4242 final __test = new VariableDeclarationTest();
4264 runJUnitTest(__test, __test.test_getDocumentationComment_onNode); 4243 runJUnitTest(__test, __test.test_getDocumentationComment_onNode);
4265 }); 4244 });
4266 }); 4245 });
4267 } 4246 }
4268 } 4247 }
4269 4248
4249 class WrapperKind extends Enum<WrapperKind> {
4250 static const WrapperKind PREFIXED_LEFT = const WrapperKind('PREFIXED_LEFT', 0) ;
4251
4252 static const WrapperKind PREFIXED_RIGHT = const WrapperKind('PREFIXED_RIGHT', 1);
4253
4254 static const WrapperKind PROPERTY_LEFT = const WrapperKind('PROPERTY_LEFT', 2) ;
4255
4256 static const WrapperKind PROPERTY_RIGHT = const WrapperKind('PROPERTY_RIGHT', 3);
4257
4258 static const WrapperKind NONE = const WrapperKind('NONE', 4);
4259
4260 static const List<WrapperKind> values = const [
4261 PREFIXED_LEFT,
4262 PREFIXED_RIGHT,
4263 PROPERTY_LEFT,
4264 PROPERTY_RIGHT,
4265 NONE];
4266
4267 const WrapperKind(String name, int ordinal) : super(name, ordinal);
4268 }
4269
4270 main() { 4270 main() {
4271 ConstantEvaluatorTest.dartSuite(); 4271 ConstantEvaluatorTest.dartSuite();
4272 NodeLocatorTest.dartSuite(); 4272 NodeLocatorTest.dartSuite();
4273 ToSourceVisitorTest.dartSuite(); 4273 ToSourceVisitorTest.dartSuite();
4274 BreadthFirstVisitorTest.dartSuite(); 4274 BreadthFirstVisitorTest.dartSuite();
4275 ClassDeclarationTest.dartSuite(); 4275 ClassDeclarationTest.dartSuite();
4276 ClassTypeAliasTest.dartSuite(); 4276 ClassTypeAliasTest.dartSuite();
4277 IndexExpressionTest.dartSuite(); 4277 IndexExpressionTest.dartSuite();
4278 NodeListTest.dartSuite(); 4278 NodeListTest.dartSuite();
4279 SimpleIdentifierTest.dartSuite(); 4279 SimpleIdentifierTest.dartSuite();
4280 SimpleStringLiteralTest.dartSuite(); 4280 SimpleStringLiteralTest.dartSuite();
4281 VariableDeclarationTest.dartSuite(); 4281 VariableDeclarationTest.dartSuite();
4282 } 4282 }
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