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

Side by Side Diff: pkg/analyzer/test/dart/element/builder_test.dart

Issue 2524903002: Rename AstFactory -> AstTestFactory. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.test.dart.element.builder_test; 5 library analyzer.test.dart.element.builder_test;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/ast/token.dart'; 8 import 'package:analyzer/dart/ast/token.dart';
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/src/dart/ast/ast.dart'; 10 import 'package:analyzer/src/dart/ast/ast.dart';
11 import 'package:analyzer/src/dart/element/builder.dart'; 11 import 'package:analyzer/src/dart/element/builder.dart';
12 import 'package:analyzer/src/dart/element/element.dart'; 12 import 'package:analyzer/src/dart/element/element.dart';
13 import 'package:analyzer/src/generated/engine.dart'; 13 import 'package:analyzer/src/generated/engine.dart';
14 import 'package:analyzer/src/generated/resolver.dart'; 14 import 'package:analyzer/src/generated/resolver.dart';
15 import 'package:analyzer/src/generated/source.dart'; 15 import 'package:analyzer/src/generated/source.dart';
16 import 'package:analyzer/src/generated/testing/ast_factory.dart'; 16 import 'package:analyzer/src/generated/testing/ast_test_factory.dart';
17 import 'package:analyzer/src/generated/testing/element_factory.dart'; 17 import 'package:analyzer/src/generated/testing/element_factory.dart';
18 import 'package:analyzer/src/generated/testing/token_factory.dart'; 18 import 'package:analyzer/src/generated/testing/token_factory.dart';
19 import 'package:analyzer/src/generated/utilities_dart.dart'; 19 import 'package:analyzer/src/generated/utilities_dart.dart';
20 import 'package:test/test.dart'; 20 import 'package:test/test.dart';
21 import 'package:test_reflective_loader/test_reflective_loader.dart'; 21 import 'package:test_reflective_loader/test_reflective_loader.dart';
22 22
23 import '../../generated/parser_test.dart'; 23 import '../../generated/parser_test.dart';
24 import '../../generated/test_support.dart'; 24 import '../../generated/test_support.dart';
25 25
26 main() { 26 main() {
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 .localVariables; 241 .localVariables;
242 String exceptionParameterName = "e"; 242 String exceptionParameterName = "e";
243 expect(variables, hasLength(1)); 243 expect(variables, hasLength(1));
244 VariableElement exceptionVariable = variables[0]; 244 VariableElement exceptionVariable = variables[0];
245 expect(exceptionVariable, isNotNull); 245 expect(exceptionVariable, isNotNull);
246 expect(exceptionVariable.name, exceptionParameterName); 246 expect(exceptionVariable.name, exceptionParameterName);
247 expect(exceptionVariable.hasImplicitType, isFalse); 247 expect(exceptionVariable.hasImplicitType, isFalse);
248 } 248 }
249 249
250 void test_visitCompilationUnit_codeRange() { 250 void test_visitCompilationUnit_codeRange() {
251 TopLevelVariableDeclaration topLevelVariableDeclaration = AstFactory 251 TopLevelVariableDeclaration topLevelVariableDeclaration = AstTestFactory
252 .topLevelVariableDeclaration(null, AstFactory.typeName4('int'), 252 .topLevelVariableDeclaration(null, AstTestFactory.typeName4('int'),
253 [AstFactory.variableDeclaration('V')]); 253 [AstTestFactory.variableDeclaration('V')]);
254 CompilationUnit unit = new CompilationUnit( 254 CompilationUnit unit = new CompilationUnit(
255 topLevelVariableDeclaration.beginToken, 255 topLevelVariableDeclaration.beginToken,
256 null, 256 null,
257 [], 257 [],
258 [topLevelVariableDeclaration], 258 [topLevelVariableDeclaration],
259 topLevelVariableDeclaration.endToken); 259 topLevelVariableDeclaration.endToken);
260 ElementHolder holder = new ElementHolder(); 260 ElementHolder holder = new ElementHolder();
261 ElementBuilder builder = _makeBuilder(holder); 261 ElementBuilder builder = _makeBuilder(holder);
262 unit.beginToken.offset = 10; 262 unit.beginToken.offset = 10;
263 unit.endToken.offset = 40; 263 unit.endToken.offset = 40;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 expect(variable.isPrivate, isFalse); 298 expect(variable.isPrivate, isFalse);
299 expect(variable.isPublic, isTrue); 299 expect(variable.isPublic, isTrue);
300 expect(variable.isSynthetic, isFalse); 300 expect(variable.isSynthetic, isFalse);
301 expect(variable.name, 'i'); 301 expect(variable.name, 'i');
302 } 302 }
303 303
304 void test_visitDefaultFormalParameter_noType() { 304 void test_visitDefaultFormalParameter_noType() {
305 // p = 0 305 // p = 0
306 String parameterName = 'p'; 306 String parameterName = 'p';
307 DefaultFormalParameter formalParameter = 307 DefaultFormalParameter formalParameter =
308 AstFactory.positionalFormalParameter( 308 AstTestFactory.positionalFormalParameter(
309 AstFactory.simpleFormalParameter3(parameterName), 309 AstTestFactory.simpleFormalParameter3(parameterName),
310 AstFactory.integer(0)); 310 AstTestFactory.integer(0));
311 formalParameter.beginToken.offset = 50; 311 formalParameter.beginToken.offset = 50;
312 formalParameter.endToken.offset = 80; 312 formalParameter.endToken.offset = 80;
313 313
314 ElementHolder holder = buildElementsForAst(formalParameter); 314 ElementHolder holder = buildElementsForAst(formalParameter);
315 List<ParameterElement> parameters = holder.parameters; 315 List<ParameterElement> parameters = holder.parameters;
316 expect(parameters, hasLength(1)); 316 expect(parameters, hasLength(1));
317 ParameterElement parameter = parameters[0]; 317 ParameterElement parameter = parameters[0];
318 assertHasCodeRange(parameter, 50, 31); 318 assertHasCodeRange(parameter, 50, 31);
319 expect(parameter.hasImplicitType, isTrue); 319 expect(parameter.hasImplicitType, isTrue);
320 expect(parameter.initializer, isNotNull); 320 expect(parameter.initializer, isNotNull);
321 expect(parameter.initializer.type, isNotNull); 321 expect(parameter.initializer.type, isNotNull);
322 expect(parameter.initializer.hasImplicitReturnType, isTrue); 322 expect(parameter.initializer.hasImplicitReturnType, isTrue);
323 expect(parameter.isConst, isFalse); 323 expect(parameter.isConst, isFalse);
324 expect(parameter.isDeprecated, isFalse); 324 expect(parameter.isDeprecated, isFalse);
325 expect(parameter.isFinal, isFalse); 325 expect(parameter.isFinal, isFalse);
326 expect(parameter.isInitializingFormal, isFalse); 326 expect(parameter.isInitializingFormal, isFalse);
327 expect(parameter.isOverride, isFalse); 327 expect(parameter.isOverride, isFalse);
328 expect(parameter.isPrivate, isFalse); 328 expect(parameter.isPrivate, isFalse);
329 expect(parameter.isPublic, isTrue); 329 expect(parameter.isPublic, isTrue);
330 expect(parameter.isSynthetic, isFalse); 330 expect(parameter.isSynthetic, isFalse);
331 expect(parameter.name, parameterName); 331 expect(parameter.name, parameterName);
332 } 332 }
333 333
334 void test_visitDefaultFormalParameter_type() { 334 void test_visitDefaultFormalParameter_type() {
335 // E p = 0 335 // E p = 0
336 String parameterName = 'p'; 336 String parameterName = 'p';
337 DefaultFormalParameter formalParameter = AstFactory.namedFormalParameter( 337 DefaultFormalParameter formalParameter =
338 AstFactory.simpleFormalParameter4( 338 AstTestFactory.namedFormalParameter(
339 AstFactory.typeName4('E'), parameterName), 339 AstTestFactory.simpleFormalParameter4(
340 AstFactory.integer(0)); 340 AstTestFactory.typeName4('E'), parameterName),
341 AstTestFactory.integer(0));
341 342
342 ElementHolder holder = buildElementsForAst(formalParameter); 343 ElementHolder holder = buildElementsForAst(formalParameter);
343 List<ParameterElement> parameters = holder.parameters; 344 List<ParameterElement> parameters = holder.parameters;
344 expect(parameters, hasLength(1)); 345 expect(parameters, hasLength(1));
345 ParameterElement parameter = parameters[0]; 346 ParameterElement parameter = parameters[0];
346 expect(parameter.hasImplicitType, isFalse); 347 expect(parameter.hasImplicitType, isFalse);
347 expect(parameter.initializer, isNotNull); 348 expect(parameter.initializer, isNotNull);
348 expect(parameter.initializer.type, isNotNull); 349 expect(parameter.initializer.type, isNotNull);
349 expect(parameter.initializer.hasImplicitReturnType, isTrue); 350 expect(parameter.initializer.hasImplicitReturnType, isTrue);
350 expect(parameter.isConst, isFalse); 351 expect(parameter.isConst, isFalse);
351 expect(parameter.isDeprecated, isFalse); 352 expect(parameter.isDeprecated, isFalse);
352 expect(parameter.isFinal, isFalse); 353 expect(parameter.isFinal, isFalse);
353 expect(parameter.isInitializingFormal, isFalse); 354 expect(parameter.isInitializingFormal, isFalse);
354 expect(parameter.isOverride, isFalse); 355 expect(parameter.isOverride, isFalse);
355 expect(parameter.isPrivate, isFalse); 356 expect(parameter.isPrivate, isFalse);
356 expect(parameter.isPublic, isTrue); 357 expect(parameter.isPublic, isTrue);
357 expect(parameter.isSynthetic, isFalse); 358 expect(parameter.isSynthetic, isFalse);
358 expect(parameter.name, parameterName); 359 expect(parameter.name, parameterName);
359 } 360 }
360 361
361 void test_visitFunctionExpression() { 362 void test_visitFunctionExpression() {
362 ElementHolder holder = new ElementHolder(); 363 ElementHolder holder = new ElementHolder();
363 ElementBuilder builder = _makeBuilder(holder); 364 ElementBuilder builder = _makeBuilder(holder);
364 FunctionExpression expression = AstFactory.functionExpression2( 365 FunctionExpression expression = AstTestFactory.functionExpression2(
365 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2()); 366 AstTestFactory.formalParameterList(),
367 AstTestFactory.blockFunctionBody2());
366 expression.accept(builder); 368 expression.accept(builder);
367 List<FunctionElement> functions = holder.functions; 369 List<FunctionElement> functions = holder.functions;
368 expect(functions, hasLength(1)); 370 expect(functions, hasLength(1));
369 FunctionElement function = functions[0]; 371 FunctionElement function = functions[0];
370 expect(function, isNotNull); 372 expect(function, isNotNull);
371 expect(expression.element, same(function)); 373 expect(expression.element, same(function));
372 expect(function.hasImplicitReturnType, isTrue); 374 expect(function.hasImplicitReturnType, isTrue);
373 expect(function.isSynthetic, isFalse); 375 expect(function.isSynthetic, isFalse);
374 expect(function.typeParameters, hasLength(0)); 376 expect(function.typeParameters, hasLength(0));
375 } 377 }
(...skipping 18 matching lines...) Expand all
394 expect(function.hasImplicitReturnType, isTrue); 396 expect(function.hasImplicitReturnType, isTrue);
395 expect(function.isSynthetic, isFalse); 397 expect(function.isSynthetic, isFalse);
396 expect(function.typeParameters, hasLength(0)); 398 expect(function.typeParameters, hasLength(0));
397 } 399 }
398 400
399 void test_visitFunctionTypeAlias() { 401 void test_visitFunctionTypeAlias() {
400 ElementHolder holder = new ElementHolder(); 402 ElementHolder holder = new ElementHolder();
401 ElementBuilder builder = _makeBuilder(holder); 403 ElementBuilder builder = _makeBuilder(holder);
402 String aliasName = "F"; 404 String aliasName = "F";
403 String parameterName = "E"; 405 String parameterName = "E";
404 FunctionTypeAlias aliasNode = AstFactory.typeAlias( 406 FunctionTypeAlias aliasNode = AstTestFactory.typeAlias(null, aliasName,
405 null, aliasName, AstFactory.typeParameterList([parameterName]), null); 407 AstTestFactory.typeParameterList([parameterName]), null);
406 aliasNode.documentationComment = AstFactory.documentationComment( 408 aliasNode.documentationComment = AstTestFactory.documentationComment(
407 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); 409 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []);
408 aliasNode.endToken.offset = 80; 410 aliasNode.endToken.offset = 80;
409 aliasNode.accept(builder); 411 aliasNode.accept(builder);
410 412
411 List<FunctionTypeAliasElement> aliases = holder.typeAliases; 413 List<FunctionTypeAliasElement> aliases = holder.typeAliases;
412 expect(aliases, hasLength(1)); 414 expect(aliases, hasLength(1));
413 FunctionTypeAliasElement alias = aliases[0]; 415 FunctionTypeAliasElement alias = aliases[0];
414 expect(alias, isNotNull); 416 expect(alias, isNotNull);
415 assertHasCodeRange(alias, 50, 31); 417 assertHasCodeRange(alias, 50, 31);
416 expect(alias.documentationComment, '/// aaa'); 418 expect(alias.documentationComment, '/// aaa');
417 expect(alias.name, aliasName); 419 expect(alias.name, aliasName);
418 expect(alias.parameters, hasLength(0)); 420 expect(alias.parameters, hasLength(0));
419 List<TypeParameterElement> typeParameters = alias.typeParameters; 421 List<TypeParameterElement> typeParameters = alias.typeParameters;
420 expect(typeParameters, hasLength(1)); 422 expect(typeParameters, hasLength(1));
421 TypeParameterElement typeParameter = typeParameters[0]; 423 TypeParameterElement typeParameter = typeParameters[0];
422 expect(typeParameter, isNotNull); 424 expect(typeParameter, isNotNull);
423 expect(typeParameter.name, parameterName); 425 expect(typeParameter.name, parameterName);
424 } 426 }
425 427
426 void test_visitFunctionTypedFormalParameter() { 428 void test_visitFunctionTypedFormalParameter() {
427 ElementHolder holder = new ElementHolder(); 429 ElementHolder holder = new ElementHolder();
428 ElementBuilder builder = _makeBuilder(holder); 430 ElementBuilder builder = _makeBuilder(holder);
429 String parameterName = "p"; 431 String parameterName = "p";
430 FunctionTypedFormalParameter formalParameter = 432 FunctionTypedFormalParameter formalParameter =
431 AstFactory.functionTypedFormalParameter(null, parameterName); 433 AstTestFactory.functionTypedFormalParameter(null, parameterName);
432 _useParameterInMethod(formalParameter, 100, 110); 434 _useParameterInMethod(formalParameter, 100, 110);
433 formalParameter.accept(builder); 435 formalParameter.accept(builder);
434 List<ParameterElement> parameters = holder.parameters; 436 List<ParameterElement> parameters = holder.parameters;
435 expect(parameters, hasLength(1)); 437 expect(parameters, hasLength(1));
436 ParameterElement parameter = parameters[0]; 438 ParameterElement parameter = parameters[0];
437 expect(parameter, isNotNull); 439 expect(parameter, isNotNull);
438 expect(parameter.name, parameterName); 440 expect(parameter.name, parameterName);
439 expect(parameter.initializer, isNull); 441 expect(parameter.initializer, isNull);
440 expect(parameter.isConst, isFalse); 442 expect(parameter.isConst, isFalse);
441 expect(parameter.isFinal, isFalse); 443 expect(parameter.isFinal, isFalse);
442 expect(parameter.isSynthetic, isFalse); 444 expect(parameter.isSynthetic, isFalse);
443 expect(parameter.parameterKind, ParameterKind.REQUIRED); 445 expect(parameter.parameterKind, ParameterKind.REQUIRED);
444 _assertVisibleRange(parameter, 100, 110); 446 _assertVisibleRange(parameter, 100, 110);
445 } 447 }
446 448
447 void test_visitFunctionTypedFormalParameter_withTypeParameters() { 449 void test_visitFunctionTypedFormalParameter_withTypeParameters() {
448 ElementHolder holder = new ElementHolder(); 450 ElementHolder holder = new ElementHolder();
449 ElementBuilder builder = _makeBuilder(holder); 451 ElementBuilder builder = _makeBuilder(holder);
450 String parameterName = "p"; 452 String parameterName = "p";
451 FunctionTypedFormalParameter formalParameter = 453 FunctionTypedFormalParameter formalParameter =
452 AstFactory.functionTypedFormalParameter(null, parameterName); 454 AstTestFactory.functionTypedFormalParameter(null, parameterName);
453 formalParameter.typeParameters = AstFactory.typeParameterList(['F']); 455 formalParameter.typeParameters = AstTestFactory.typeParameterList(['F']);
454 _useParameterInMethod(formalParameter, 100, 110); 456 _useParameterInMethod(formalParameter, 100, 110);
455 formalParameter.accept(builder); 457 formalParameter.accept(builder);
456 List<ParameterElement> parameters = holder.parameters; 458 List<ParameterElement> parameters = holder.parameters;
457 expect(parameters, hasLength(1)); 459 expect(parameters, hasLength(1));
458 ParameterElement parameter = parameters[0]; 460 ParameterElement parameter = parameters[0];
459 expect(parameter, isNotNull); 461 expect(parameter, isNotNull);
460 expect(parameter.name, parameterName); 462 expect(parameter.name, parameterName);
461 expect(parameter.initializer, isNull); 463 expect(parameter.initializer, isNull);
462 expect(parameter.isConst, isFalse); 464 expect(parameter.isConst, isFalse);
463 expect(parameter.isFinal, isFalse); 465 expect(parameter.isFinal, isFalse);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 expect(labels, hasLength(1)); 518 expect(labels, hasLength(1));
517 LabelElement label = labels[0]; 519 LabelElement label = labels[0];
518 expect(label, isNotNull); 520 expect(label, isNotNull);
519 expect(label.name, labelName); 521 expect(label.name, labelName);
520 } 522 }
521 523
522 void test_visitNamedFormalParameter() { 524 void test_visitNamedFormalParameter() {
523 ElementHolder holder = new ElementHolder(); 525 ElementHolder holder = new ElementHolder();
524 ElementBuilder builder = _makeBuilder(holder); 526 ElementBuilder builder = _makeBuilder(holder);
525 String parameterName = "p"; 527 String parameterName = "p";
526 DefaultFormalParameter formalParameter = AstFactory.namedFormalParameter( 528 DefaultFormalParameter formalParameter =
527 AstFactory.simpleFormalParameter3(parameterName), 529 AstTestFactory.namedFormalParameter(
528 AstFactory.identifier3("42")); 530 AstTestFactory.simpleFormalParameter3(parameterName),
531 AstTestFactory.identifier3("42"));
529 _useParameterInMethod(formalParameter, 100, 110); 532 _useParameterInMethod(formalParameter, 100, 110);
530 formalParameter.beginToken.offset = 50; 533 formalParameter.beginToken.offset = 50;
531 formalParameter.endToken.offset = 80; 534 formalParameter.endToken.offset = 80;
532 formalParameter.accept(builder); 535 formalParameter.accept(builder);
533 List<ParameterElement> parameters = holder.parameters; 536 List<ParameterElement> parameters = holder.parameters;
534 expect(parameters, hasLength(1)); 537 expect(parameters, hasLength(1));
535 ParameterElement parameter = parameters[0]; 538 ParameterElement parameter = parameters[0];
536 expect(parameter, isNotNull); 539 expect(parameter, isNotNull);
537 assertHasCodeRange(parameter, 50, 32); 540 assertHasCodeRange(parameter, 50, 32);
538 expect(parameter.name, parameterName); 541 expect(parameter.name, parameterName);
539 expect(parameter.isConst, isFalse); 542 expect(parameter.isConst, isFalse);
540 expect(parameter.isFinal, isFalse); 543 expect(parameter.isFinal, isFalse);
541 expect(parameter.isSynthetic, isFalse); 544 expect(parameter.isSynthetic, isFalse);
542 expect(parameter.parameterKind, ParameterKind.NAMED); 545 expect(parameter.parameterKind, ParameterKind.NAMED);
543 _assertVisibleRange(parameter, 100, 110); 546 _assertVisibleRange(parameter, 100, 110);
544 expect(parameter.defaultValueCode, "42"); 547 expect(parameter.defaultValueCode, "42");
545 FunctionElement initializer = parameter.initializer; 548 FunctionElement initializer = parameter.initializer;
546 expect(initializer, isNotNull); 549 expect(initializer, isNotNull);
547 expect(initializer.isSynthetic, isTrue); 550 expect(initializer.isSynthetic, isTrue);
548 expect(initializer.hasImplicitReturnType, isTrue); 551 expect(initializer.hasImplicitReturnType, isTrue);
549 } 552 }
550 553
551 void test_visitSimpleFormalParameter_noType() { 554 void test_visitSimpleFormalParameter_noType() {
552 // p 555 // p
553 ElementHolder holder = new ElementHolder(); 556 ElementHolder holder = new ElementHolder();
554 ElementBuilder builder = _makeBuilder(holder); 557 ElementBuilder builder = _makeBuilder(holder);
555 String parameterName = "p"; 558 String parameterName = "p";
556 SimpleFormalParameter formalParameter = 559 SimpleFormalParameter formalParameter =
557 AstFactory.simpleFormalParameter3(parameterName); 560 AstTestFactory.simpleFormalParameter3(parameterName);
558 _useParameterInMethod(formalParameter, 100, 110); 561 _useParameterInMethod(formalParameter, 100, 110);
559 formalParameter.accept(builder); 562 formalParameter.accept(builder);
560 List<ParameterElement> parameters = holder.parameters; 563 List<ParameterElement> parameters = holder.parameters;
561 expect(parameters, hasLength(1)); 564 expect(parameters, hasLength(1));
562 ParameterElement parameter = parameters[0]; 565 ParameterElement parameter = parameters[0];
563 expect(parameter, isNotNull); 566 expect(parameter, isNotNull);
564 expect(parameter.hasImplicitType, isTrue); 567 expect(parameter.hasImplicitType, isTrue);
565 expect(parameter.initializer, isNull); 568 expect(parameter.initializer, isNull);
566 expect(parameter.isConst, isFalse); 569 expect(parameter.isConst, isFalse);
567 expect(parameter.isFinal, isFalse); 570 expect(parameter.isFinal, isFalse);
568 expect(parameter.isSynthetic, isFalse); 571 expect(parameter.isSynthetic, isFalse);
569 expect(parameter.name, parameterName); 572 expect(parameter.name, parameterName);
570 expect(parameter.parameterKind, ParameterKind.REQUIRED); 573 expect(parameter.parameterKind, ParameterKind.REQUIRED);
571 _assertVisibleRange(parameter, 100, 110); 574 _assertVisibleRange(parameter, 100, 110);
572 } 575 }
573 576
574 void test_visitSimpleFormalParameter_type() { 577 void test_visitSimpleFormalParameter_type() {
575 // T p 578 // T p
576 ElementHolder holder = new ElementHolder(); 579 ElementHolder holder = new ElementHolder();
577 ElementBuilder builder = _makeBuilder(holder); 580 ElementBuilder builder = _makeBuilder(holder);
578 String parameterName = "p"; 581 String parameterName = "p";
579 SimpleFormalParameter formalParameter = AstFactory.simpleFormalParameter4( 582 SimpleFormalParameter formalParameter = AstTestFactory
580 AstFactory.typeName4('T'), parameterName); 583 .simpleFormalParameter4(AstTestFactory.typeName4('T'), parameterName);
581 _useParameterInMethod(formalParameter, 100, 110); 584 _useParameterInMethod(formalParameter, 100, 110);
582 formalParameter.accept(builder); 585 formalParameter.accept(builder);
583 List<ParameterElement> parameters = holder.parameters; 586 List<ParameterElement> parameters = holder.parameters;
584 expect(parameters, hasLength(1)); 587 expect(parameters, hasLength(1));
585 ParameterElement parameter = parameters[0]; 588 ParameterElement parameter = parameters[0];
586 expect(parameter, isNotNull); 589 expect(parameter, isNotNull);
587 expect(parameter.hasImplicitType, isFalse); 590 expect(parameter.hasImplicitType, isFalse);
588 expect(parameter.initializer, isNull); 591 expect(parameter.initializer, isNull);
589 expect(parameter.isConst, isFalse); 592 expect(parameter.isConst, isFalse);
590 expect(parameter.isFinal, isFalse); 593 expect(parameter.isFinal, isFalse);
(...skipping 19 matching lines...) Expand all
610 _assertVisibleRange(variableElement, 14, 28); 613 _assertVisibleRange(variableElement, 14, 28);
611 } 614 }
612 615
613 void test_visitVariableDeclaration_inForEachStatement() { 616 void test_visitVariableDeclaration_inForEachStatement() {
614 ElementHolder holder = new ElementHolder(); 617 ElementHolder holder = new ElementHolder();
615 ElementBuilder builder = _makeBuilder(holder); 618 ElementBuilder builder = _makeBuilder(holder);
616 // 619 //
617 // m() { for (var v in []) } 620 // m() { for (var v in []) }
618 // 621 //
619 String variableName = "v"; 622 String variableName = "v";
620 Statement statement = AstFactory.forEachStatement( 623 Statement statement = AstTestFactory.forEachStatement(
621 AstFactory.declaredIdentifier3('v'), 624 AstTestFactory.declaredIdentifier3('v'),
622 AstFactory.listLiteral(), 625 AstTestFactory.listLiteral(),
623 AstFactory.block()); 626 AstTestFactory.block());
624 _setNodeSourceRange(statement, 100, 110); 627 _setNodeSourceRange(statement, 100, 110);
625 MethodDeclaration method = AstFactory.methodDeclaration2( 628 MethodDeclaration method = AstTestFactory.methodDeclaration2(
626 null, 629 null,
627 null, 630 null,
628 null, 631 null,
629 null, 632 null,
630 AstFactory.identifier3("m"), 633 AstTestFactory.identifier3("m"),
631 AstFactory.formalParameterList(), 634 AstTestFactory.formalParameterList(),
632 AstFactory.blockFunctionBody2([statement])); 635 AstTestFactory.blockFunctionBody2([statement]));
633 _setBlockBodySourceRange(method.body, 200, 220); 636 _setBlockBodySourceRange(method.body, 200, 220);
634 method.accept(builder); 637 method.accept(builder);
635 638
636 List<MethodElement> methods = holder.methods; 639 List<MethodElement> methods = holder.methods;
637 expect(methods, hasLength(1)); 640 expect(methods, hasLength(1));
638 List<LocalVariableElement> variableElements = methods[0].localVariables; 641 List<LocalVariableElement> variableElements = methods[0].localVariables;
639 expect(variableElements, hasLength(1)); 642 expect(variableElements, hasLength(1));
640 LocalVariableElement variableElement = variableElements[0]; 643 LocalVariableElement variableElement = variableElements[0];
641 expect(variableElement.name, variableName); 644 expect(variableElement.name, variableName);
642 _assertVisibleRange(variableElement, 100, 110); 645 _assertVisibleRange(variableElement, 100, 110);
643 } 646 }
644 647
645 void test_visitVariableDeclaration_inForStatement() { 648 void test_visitVariableDeclaration_inForStatement() {
646 ElementHolder holder = new ElementHolder(); 649 ElementHolder holder = new ElementHolder();
647 ElementBuilder builder = _makeBuilder(holder); 650 ElementBuilder builder = _makeBuilder(holder);
648 // 651 //
649 // m() { for (T v;;) } 652 // m() { for (T v;;) }
650 // 653 //
651 String variableName = "v"; 654 String variableName = "v";
652 ForStatement statement = AstFactory.forStatement2( 655 ForStatement statement = AstTestFactory.forStatement2(
653 AstFactory.variableDeclarationList(null, AstFactory.typeName4('T'), 656 AstTestFactory.variableDeclarationList(
654 [AstFactory.variableDeclaration('v')]), 657 null,
658 AstTestFactory.typeName4('T'),
659 [AstTestFactory.variableDeclaration('v')]),
655 null, 660 null,
656 null, 661 null,
657 AstFactory.block()); 662 AstTestFactory.block());
658 _setNodeSourceRange(statement, 100, 110); 663 _setNodeSourceRange(statement, 100, 110);
659 MethodDeclaration method = AstFactory.methodDeclaration2( 664 MethodDeclaration method = AstTestFactory.methodDeclaration2(
660 null, 665 null,
661 null, 666 null,
662 null, 667 null,
663 null, 668 null,
664 AstFactory.identifier3("m"), 669 AstTestFactory.identifier3("m"),
665 AstFactory.formalParameterList(), 670 AstTestFactory.formalParameterList(),
666 AstFactory.blockFunctionBody2([statement])); 671 AstTestFactory.blockFunctionBody2([statement]));
667 _setBlockBodySourceRange(method.body, 200, 220); 672 _setBlockBodySourceRange(method.body, 200, 220);
668 method.accept(builder); 673 method.accept(builder);
669 674
670 List<MethodElement> methods = holder.methods; 675 List<MethodElement> methods = holder.methods;
671 expect(methods, hasLength(1)); 676 expect(methods, hasLength(1));
672 List<LocalVariableElement> variableElements = methods[0].localVariables; 677 List<LocalVariableElement> variableElements = methods[0].localVariables;
673 expect(variableElements, hasLength(1)); 678 expect(variableElements, hasLength(1));
674 LocalVariableElement variableElement = variableElements[0]; 679 LocalVariableElement variableElement = variableElements[0];
675 expect(variableElement.name, variableName); 680 expect(variableElement.name, variableName);
676 _assertVisibleRange(variableElement, 100, 110); 681 _assertVisibleRange(variableElement, 100, 110);
677 } 682 }
678 683
679 void test_visitVariableDeclaration_inMethod() { 684 void test_visitVariableDeclaration_inMethod() {
680 ElementHolder holder = new ElementHolder(); 685 ElementHolder holder = new ElementHolder();
681 ElementBuilder builder = _makeBuilder(holder); 686 ElementBuilder builder = _makeBuilder(holder);
682 // 687 //
683 // m() {T v;} 688 // m() {T v;}
684 // 689 //
685 String variableName = "v"; 690 String variableName = "v";
686 VariableDeclaration variable = 691 VariableDeclaration variable =
687 AstFactory.variableDeclaration2(variableName, null); 692 AstTestFactory.variableDeclaration2(variableName, null);
688 Statement statement = AstFactory.variableDeclarationStatement( 693 Statement statement = AstTestFactory.variableDeclarationStatement(
689 null, AstFactory.typeName4('T'), [variable]); 694 null, AstTestFactory.typeName4('T'), [variable]);
690 MethodDeclaration method = AstFactory.methodDeclaration2( 695 MethodDeclaration method = AstTestFactory.methodDeclaration2(
691 null, 696 null,
692 null, 697 null,
693 null, 698 null,
694 null, 699 null,
695 AstFactory.identifier3("m"), 700 AstTestFactory.identifier3("m"),
696 AstFactory.formalParameterList(), 701 AstTestFactory.formalParameterList(),
697 AstFactory.blockFunctionBody2([statement])); 702 AstTestFactory.blockFunctionBody2([statement]));
698 _setBlockBodySourceRange(method.body, 100, 110); 703 _setBlockBodySourceRange(method.body, 100, 110);
699 method.accept(builder); 704 method.accept(builder);
700 705
701 List<MethodElement> methods = holder.methods; 706 List<MethodElement> methods = holder.methods;
702 expect(methods, hasLength(1)); 707 expect(methods, hasLength(1));
703 List<LocalVariableElement> variableElements = methods[0].localVariables; 708 List<LocalVariableElement> variableElements = methods[0].localVariables;
704 expect(variableElements, hasLength(1)); 709 expect(variableElements, hasLength(1));
705 LocalVariableElement variableElement = variableElements[0]; 710 LocalVariableElement variableElement = variableElements[0];
706 expect(variableElement.hasImplicitType, isFalse); 711 expect(variableElement.hasImplicitType, isFalse);
707 expect(variableElement.name, variableName); 712 expect(variableElement.name, variableName);
708 _assertVisibleRange(variableElement, 100, 110); 713 _assertVisibleRange(variableElement, 100, 110);
709 } 714 }
710 715
711 void test_visitVariableDeclaration_localNestedInFunction() { 716 void test_visitVariableDeclaration_localNestedInFunction() {
712 ElementHolder holder = new ElementHolder(); 717 ElementHolder holder = new ElementHolder();
713 ElementBuilder builder = _makeBuilder(holder); 718 ElementBuilder builder = _makeBuilder(holder);
714 // 719 //
715 // var f = () {var v;}; 720 // var f = () {var v;};
716 // 721 //
717 String variableName = "v"; 722 String variableName = "v";
718 VariableDeclaration variable = 723 VariableDeclaration variable =
719 AstFactory.variableDeclaration2(variableName, null); 724 AstTestFactory.variableDeclaration2(variableName, null);
720 Statement statement = 725 Statement statement =
721 AstFactory.variableDeclarationStatement2(null, [variable]); 726 AstTestFactory.variableDeclarationStatement2(null, [variable]);
722 Expression initializer = AstFactory.functionExpression2( 727 Expression initializer = AstTestFactory.functionExpression2(
723 AstFactory.formalParameterList(), 728 AstTestFactory.formalParameterList(),
724 AstFactory.blockFunctionBody2([statement])); 729 AstTestFactory.blockFunctionBody2([statement]));
725 String fieldName = "f"; 730 String fieldName = "f";
726 VariableDeclaration field = 731 VariableDeclaration field =
727 AstFactory.variableDeclaration2(fieldName, initializer); 732 AstTestFactory.variableDeclaration2(fieldName, initializer);
728 FieldDeclaration fieldDeclaration = 733 FieldDeclaration fieldDeclaration =
729 AstFactory.fieldDeclaration2(false, null, [field]); 734 AstTestFactory.fieldDeclaration2(false, null, [field]);
730 fieldDeclaration.accept(builder); 735 fieldDeclaration.accept(builder);
731 736
732 List<FieldElement> variables = holder.fields; 737 List<FieldElement> variables = holder.fields;
733 expect(variables, hasLength(1)); 738 expect(variables, hasLength(1));
734 FieldElement fieldElement = variables[0]; 739 FieldElement fieldElement = variables[0];
735 expect(fieldElement, isNotNull); 740 expect(fieldElement, isNotNull);
736 FunctionElement initializerElement = fieldElement.initializer; 741 FunctionElement initializerElement = fieldElement.initializer;
737 expect(initializerElement, isNotNull); 742 expect(initializerElement, isNotNull);
738 expect(initializerElement.hasImplicitReturnType, isTrue); 743 expect(initializerElement.hasImplicitReturnType, isTrue);
739 List<FunctionElement> functionElements = initializerElement.functions; 744 List<FunctionElement> functionElements = initializerElement.functions;
740 expect(functionElements, hasLength(1)); 745 expect(functionElements, hasLength(1));
741 List<LocalVariableElement> variableElements = 746 List<LocalVariableElement> variableElements =
742 functionElements[0].localVariables; 747 functionElements[0].localVariables;
743 expect(variableElements, hasLength(1)); 748 expect(variableElements, hasLength(1));
744 LocalVariableElement variableElement = variableElements[0]; 749 LocalVariableElement variableElement = variableElements[0];
745 expect(variableElement.hasImplicitType, isTrue); 750 expect(variableElement.hasImplicitType, isTrue);
746 expect(variableElement.isConst, isFalse); 751 expect(variableElement.isConst, isFalse);
747 expect(variableElement.isFinal, isFalse); 752 expect(variableElement.isFinal, isFalse);
748 expect(variableElement.isSynthetic, isFalse); 753 expect(variableElement.isSynthetic, isFalse);
749 expect(variableElement.name, variableName); 754 expect(variableElement.name, variableName);
750 } 755 }
751 756
752 void test_visitVariableDeclaration_noInitializer() { 757 void test_visitVariableDeclaration_noInitializer() {
753 // var v; 758 // var v;
754 ElementHolder holder = new ElementHolder(); 759 ElementHolder holder = new ElementHolder();
755 ElementBuilder builder = _makeBuilder(holder); 760 ElementBuilder builder = _makeBuilder(holder);
756 String variableName = "v"; 761 String variableName = "v";
757 VariableDeclaration variableDeclaration = 762 VariableDeclaration variableDeclaration =
758 AstFactory.variableDeclaration2(variableName, null); 763 AstTestFactory.variableDeclaration2(variableName, null);
759 AstFactory.variableDeclarationList2(null, [variableDeclaration]); 764 AstTestFactory.variableDeclarationList2(null, [variableDeclaration]);
760 variableDeclaration.accept(builder); 765 variableDeclaration.accept(builder);
761 766
762 List<TopLevelVariableElement> variables = holder.topLevelVariables; 767 List<TopLevelVariableElement> variables = holder.topLevelVariables;
763 expect(variables, hasLength(1)); 768 expect(variables, hasLength(1));
764 TopLevelVariableElement variable = variables[0]; 769 TopLevelVariableElement variable = variables[0];
765 expect(variable, isNotNull); 770 expect(variable, isNotNull);
766 expect(variable.hasImplicitType, isTrue); 771 expect(variable.hasImplicitType, isTrue);
767 expect(variable.initializer, isNull); 772 expect(variable.initializer, isNull);
768 expect(variable.name, variableName); 773 expect(variable.name, variableName);
769 expect(variable.isConst, isFalse); 774 expect(variable.isConst, isFalse);
770 expect(variable.isFinal, isFalse); 775 expect(variable.isFinal, isFalse);
771 expect(variable.isSynthetic, isFalse); 776 expect(variable.isSynthetic, isFalse);
772 expect(variable.getter, isNotNull); 777 expect(variable.getter, isNotNull);
773 expect(variable.setter, isNotNull); 778 expect(variable.setter, isNotNull);
774 } 779 }
775 780
776 void test_visitVariableDeclaration_top() { 781 void test_visitVariableDeclaration_top() {
777 // final a, b; 782 // final a, b;
778 ElementHolder holder = new ElementHolder(); 783 ElementHolder holder = new ElementHolder();
779 ElementBuilder builder = _makeBuilder(holder); 784 ElementBuilder builder = _makeBuilder(holder);
780 VariableDeclaration variableDeclaration1 = 785 VariableDeclaration variableDeclaration1 =
781 AstFactory.variableDeclaration('a'); 786 AstTestFactory.variableDeclaration('a');
782 VariableDeclaration variableDeclaration2 = 787 VariableDeclaration variableDeclaration2 =
783 AstFactory.variableDeclaration('b'); 788 AstTestFactory.variableDeclaration('b');
784 TopLevelVariableDeclaration topLevelVariableDeclaration = AstFactory 789 TopLevelVariableDeclaration topLevelVariableDeclaration = AstTestFactory
785 .topLevelVariableDeclaration( 790 .topLevelVariableDeclaration(
786 Keyword.FINAL, null, [variableDeclaration1, variableDeclaration2]); 791 Keyword.FINAL, null, [variableDeclaration1, variableDeclaration2]);
787 topLevelVariableDeclaration.documentationComment = AstFactory 792 topLevelVariableDeclaration.documentationComment = AstTestFactory
788 .documentationComment( 793 .documentationComment(
789 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); 794 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []);
790 795
791 topLevelVariableDeclaration.accept(builder); 796 topLevelVariableDeclaration.accept(builder);
792 List<TopLevelVariableElement> variables = holder.topLevelVariables; 797 List<TopLevelVariableElement> variables = holder.topLevelVariables;
793 expect(variables, hasLength(2)); 798 expect(variables, hasLength(2));
794 799
795 TopLevelVariableElement variable1 = variables[0]; 800 TopLevelVariableElement variable1 = variables[0];
796 expect(variable1, isNotNull); 801 expect(variable1, isNotNull);
797 expect(variable1.documentationComment, '/// aaa'); 802 expect(variable1.documentationComment, '/// aaa');
798 803
799 TopLevelVariableElement variable2 = variables[1]; 804 TopLevelVariableElement variable2 = variables[1];
800 expect(variable2, isNotNull); 805 expect(variable2, isNotNull);
801 expect(variable2.documentationComment, '/// aaa'); 806 expect(variable2.documentationComment, '/// aaa');
802 } 807 }
803 808
804 void test_visitVariableDeclaration_top_const_hasInitializer() { 809 void test_visitVariableDeclaration_top_const_hasInitializer() {
805 // const v = 42; 810 // const v = 42;
806 ElementHolder holder = new ElementHolder(); 811 ElementHolder holder = new ElementHolder();
807 ElementBuilder builder = _makeBuilder(holder); 812 ElementBuilder builder = _makeBuilder(holder);
808 String variableName = "v"; 813 String variableName = "v";
809 VariableDeclaration variableDeclaration = 814 VariableDeclaration variableDeclaration = AstTestFactory
810 AstFactory.variableDeclaration2(variableName, AstFactory.integer(42)); 815 .variableDeclaration2(variableName, AstTestFactory.integer(42));
811 AstFactory.variableDeclarationList2(Keyword.CONST, [variableDeclaration]); 816 AstTestFactory
817 .variableDeclarationList2(Keyword.CONST, [variableDeclaration]);
812 variableDeclaration.accept(builder); 818 variableDeclaration.accept(builder);
813 819
814 List<TopLevelVariableElement> variables = holder.topLevelVariables; 820 List<TopLevelVariableElement> variables = holder.topLevelVariables;
815 expect(variables, hasLength(1)); 821 expect(variables, hasLength(1));
816 TopLevelVariableElement variable = variables[0]; 822 TopLevelVariableElement variable = variables[0];
817 expect(variable, new isInstanceOf<ConstTopLevelVariableElementImpl>()); 823 expect(variable, new isInstanceOf<ConstTopLevelVariableElementImpl>());
818 expect(variable.initializer, isNotNull); 824 expect(variable.initializer, isNotNull);
819 expect(variable.initializer.type, isNotNull); 825 expect(variable.initializer.type, isNotNull);
820 expect(variable.initializer.hasImplicitReturnType, isTrue); 826 expect(variable.initializer.hasImplicitReturnType, isTrue);
821 expect(variable.name, variableName); 827 expect(variable.name, variableName);
822 expect(variable.hasImplicitType, isTrue); 828 expect(variable.hasImplicitType, isTrue);
823 expect(variable.isConst, isTrue); 829 expect(variable.isConst, isTrue);
824 expect(variable.isFinal, isFalse); 830 expect(variable.isFinal, isFalse);
825 expect(variable.isSynthetic, isFalse); 831 expect(variable.isSynthetic, isFalse);
826 expect(variable.getter, isNotNull); 832 expect(variable.getter, isNotNull);
827 expect(variable.setter, isNull); 833 expect(variable.setter, isNull);
828 } 834 }
829 835
830 void test_visitVariableDeclaration_top_final() { 836 void test_visitVariableDeclaration_top_final() {
831 // final v; 837 // final v;
832 ElementHolder holder = new ElementHolder(); 838 ElementHolder holder = new ElementHolder();
833 ElementBuilder builder = _makeBuilder(holder); 839 ElementBuilder builder = _makeBuilder(holder);
834 String variableName = "v"; 840 String variableName = "v";
835 VariableDeclaration variableDeclaration = 841 VariableDeclaration variableDeclaration =
836 AstFactory.variableDeclaration2(variableName, null); 842 AstTestFactory.variableDeclaration2(variableName, null);
837 AstFactory.variableDeclarationList2(Keyword.FINAL, [variableDeclaration]); 843 AstTestFactory
844 .variableDeclarationList2(Keyword.FINAL, [variableDeclaration]);
838 variableDeclaration.accept(builder); 845 variableDeclaration.accept(builder);
839 List<TopLevelVariableElement> variables = holder.topLevelVariables; 846 List<TopLevelVariableElement> variables = holder.topLevelVariables;
840 expect(variables, hasLength(1)); 847 expect(variables, hasLength(1));
841 TopLevelVariableElement variable = variables[0]; 848 TopLevelVariableElement variable = variables[0];
842 expect(variable, isNotNull); 849 expect(variable, isNotNull);
843 expect(variable.hasImplicitType, isTrue); 850 expect(variable.hasImplicitType, isTrue);
844 expect(variable.initializer, isNull); 851 expect(variable.initializer, isNull);
845 expect(variable.name, variableName); 852 expect(variable.name, variableName);
846 expect(variable.isConst, isFalse); 853 expect(variable.isConst, isFalse);
847 expect(variable.isFinal, isTrue); 854 expect(variable.isFinal, isTrue);
(...skipping 10 matching lines...) Expand all
858 } 865 }
859 866
860 void _setNodeSourceRange(AstNode node, int offset, int end) { 867 void _setNodeSourceRange(AstNode node, int offset, int end) {
861 node.beginToken.offset = offset; 868 node.beginToken.offset = offset;
862 Token endToken = node.endToken; 869 Token endToken = node.endToken;
863 endToken.offset = end - endToken.length; 870 endToken.offset = end - endToken.length;
864 } 871 }
865 872
866 void _useParameterInMethod( 873 void _useParameterInMethod(
867 FormalParameter formalParameter, int blockOffset, int blockEnd) { 874 FormalParameter formalParameter, int blockOffset, int blockEnd) {
868 Block block = AstFactory.block(); 875 Block block = AstTestFactory.block();
869 block.leftBracket.offset = blockOffset; 876 block.leftBracket.offset = blockOffset;
870 block.rightBracket.offset = blockEnd - 1; 877 block.rightBracket.offset = blockEnd - 1;
871 BlockFunctionBody body = AstFactory.blockFunctionBody(block); 878 BlockFunctionBody body = AstTestFactory.blockFunctionBody(block);
872 AstFactory.methodDeclaration2( 879 AstTestFactory.methodDeclaration2(
873 null, 880 null,
874 null, 881 null,
875 null, 882 null,
876 null, 883 null,
877 AstFactory.identifier3("main"), 884 AstTestFactory.identifier3("main"),
878 AstFactory.formalParameterList([formalParameter]), 885 AstTestFactory.formalParameterList([formalParameter]),
879 body); 886 body);
880 } 887 }
881 } 888 }
882 889
883 @reflectiveTest 890 @reflectiveTest
884 class LocalElementBuilderTest extends _BaseTest { 891 class LocalElementBuilderTest extends _BaseTest {
885 @override 892 @override
886 AstVisitor createElementBuilder(ElementHolder holder) { 893 AstVisitor createElementBuilder(ElementHolder holder) {
887 return new LocalElementBuilder(holder, compilationUnitElement); 894 return new LocalElementBuilder(holder, compilationUnitElement);
888 } 895 }
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
1255 ElementHolder holder = buildElementsForText(code); 1262 ElementHolder holder = buildElementsForText(code);
1256 ClassElement elementC = holder.types[1]; 1263 ClassElement elementC = holder.types[1];
1257 expect(elementC, isNotNull); 1264 expect(elementC, isNotNull);
1258 MethodElement methodM = elementC.methods[0]; 1265 MethodElement methodM = elementC.methods[0];
1259 expect(methodM, isNotNull); 1266 expect(methodM, isNotNull);
1260 expect(methodM.functions, isEmpty); 1267 expect(methodM.functions, isEmpty);
1261 } 1268 }
1262 1269
1263 void test_visitClassDeclaration_minimal() { 1270 void test_visitClassDeclaration_minimal() {
1264 String className = "C"; 1271 String className = "C";
1265 ClassDeclaration classDeclaration = 1272 ClassDeclaration classDeclaration = AstTestFactory.classDeclaration(
1266 AstFactory.classDeclaration(null, className, null, null, null, null); 1273 null, className, null, null, null, null);
1267 classDeclaration.documentationComment = AstFactory.documentationComment( 1274 classDeclaration.documentationComment = AstTestFactory.documentationComment(
1268 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); 1275 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []);
1269 classDeclaration.endToken.offset = 80; 1276 classDeclaration.endToken.offset = 80;
1270 1277
1271 ElementHolder holder = buildElementsForAst(classDeclaration); 1278 ElementHolder holder = buildElementsForAst(classDeclaration);
1272 List<ClassElement> types = holder.types; 1279 List<ClassElement> types = holder.types;
1273 expect(types, hasLength(1)); 1280 expect(types, hasLength(1));
1274 ClassElement type = types[0]; 1281 ClassElement type = types[0];
1275 expect(type, isNotNull); 1282 expect(type, isNotNull);
1276 expect(type.name, className); 1283 expect(type.name, className);
1277 List<TypeParameterElement> typeParameters = type.typeParameters; 1284 List<TypeParameterElement> typeParameters = type.typeParameters;
1278 expect(typeParameters, hasLength(0)); 1285 expect(typeParameters, hasLength(0));
1279 expect(type.isAbstract, isFalse); 1286 expect(type.isAbstract, isFalse);
1280 expect(type.isMixinApplication, isFalse); 1287 expect(type.isMixinApplication, isFalse);
1281 expect(type.isSynthetic, isFalse); 1288 expect(type.isSynthetic, isFalse);
1282 expect(type.documentationComment, '/// aaa'); 1289 expect(type.documentationComment, '/// aaa');
1283 assertHasCodeRange(type, 50, 31); 1290 assertHasCodeRange(type, 50, 31);
1284 } 1291 }
1285 1292
1286 void test_visitClassDeclaration_parameterized() { 1293 void test_visitClassDeclaration_parameterized() {
1287 String className = "C"; 1294 String className = "C";
1288 String firstVariableName = "E"; 1295 String firstVariableName = "E";
1289 String secondVariableName = "F"; 1296 String secondVariableName = "F";
1290 ClassDeclaration classDeclaration = AstFactory.classDeclaration( 1297 ClassDeclaration classDeclaration = AstTestFactory.classDeclaration(
1291 null, 1298 null,
1292 className, 1299 className,
1293 AstFactory.typeParameterList([firstVariableName, secondVariableName]), 1300 AstTestFactory
1301 .typeParameterList([firstVariableName, secondVariableName]),
1294 null, 1302 null,
1295 null, 1303 null,
1296 null); 1304 null);
1297 1305
1298 ElementHolder holder = buildElementsForAst(classDeclaration); 1306 ElementHolder holder = buildElementsForAst(classDeclaration);
1299 List<ClassElement> types = holder.types; 1307 List<ClassElement> types = holder.types;
1300 expect(types, hasLength(1)); 1308 expect(types, hasLength(1));
1301 ClassElement type = types[0]; 1309 ClassElement type = types[0];
1302 expect(type, isNotNull); 1310 expect(type, isNotNull);
1303 expect(type.name, className); 1311 expect(type.name, className);
1304 List<TypeParameterElement> typeParameters = type.typeParameters; 1312 List<TypeParameterElement> typeParameters = type.typeParameters;
1305 expect(typeParameters, hasLength(2)); 1313 expect(typeParameters, hasLength(2));
1306 expect(typeParameters[0].name, firstVariableName); 1314 expect(typeParameters[0].name, firstVariableName);
1307 expect(typeParameters[1].name, secondVariableName); 1315 expect(typeParameters[1].name, secondVariableName);
1308 expect(type.isAbstract, isFalse); 1316 expect(type.isAbstract, isFalse);
1309 expect(type.isMixinApplication, isFalse); 1317 expect(type.isMixinApplication, isFalse);
1310 expect(type.isSynthetic, isFalse); 1318 expect(type.isSynthetic, isFalse);
1311 } 1319 }
1312 1320
1313 void test_visitClassDeclaration_withMembers() { 1321 void test_visitClassDeclaration_withMembers() {
1314 String className = "C"; 1322 String className = "C";
1315 String typeParameterName = "E"; 1323 String typeParameterName = "E";
1316 String fieldName = "f"; 1324 String fieldName = "f";
1317 String methodName = "m"; 1325 String methodName = "m";
1318 ClassDeclaration classDeclaration = AstFactory.classDeclaration( 1326 ClassDeclaration classDeclaration = AstTestFactory.classDeclaration(
1319 null, 1327 null,
1320 className, 1328 className,
1321 AstFactory.typeParameterList([typeParameterName]), 1329 AstTestFactory.typeParameterList([typeParameterName]),
1322 null, 1330 null,
1323 null, 1331 null,
1324 null, [ 1332 null, [
1325 AstFactory.fieldDeclaration2( 1333 AstTestFactory.fieldDeclaration2(
1326 false, null, [AstFactory.variableDeclaration(fieldName)]), 1334 false, null, [AstTestFactory.variableDeclaration(fieldName)]),
1327 AstFactory.methodDeclaration2( 1335 AstTestFactory.methodDeclaration2(
1328 null, 1336 null,
1329 null, 1337 null,
1330 null, 1338 null,
1331 null, 1339 null,
1332 AstFactory.identifier3(methodName), 1340 AstTestFactory.identifier3(methodName),
1333 AstFactory.formalParameterList(), 1341 AstTestFactory.formalParameterList(),
1334 AstFactory.blockFunctionBody2()) 1342 AstTestFactory.blockFunctionBody2())
1335 ]); 1343 ]);
1336 1344
1337 ElementHolder holder = buildElementsForAst(classDeclaration); 1345 ElementHolder holder = buildElementsForAst(classDeclaration);
1338 List<ClassElement> types = holder.types; 1346 List<ClassElement> types = holder.types;
1339 expect(types, hasLength(1)); 1347 expect(types, hasLength(1));
1340 ClassElement type = types[0]; 1348 ClassElement type = types[0];
1341 expect(type, isNotNull); 1349 expect(type, isNotNull);
1342 expect(type.name, className); 1350 expect(type.name, className);
1343 expect(type.isAbstract, isFalse); 1351 expect(type.isAbstract, isFalse);
1344 expect(type.isMixinApplication, isFalse); 1352 expect(type.isMixinApplication, isFalse);
(...skipping 19 matching lines...) Expand all
1364 // class B {} 1372 // class B {}
1365 // class M {} 1373 // class M {}
1366 // class C = B with M 1374 // class C = B with M
1367 ClassElementImpl classB = ElementFactory.classElement2('B', []); 1375 ClassElementImpl classB = ElementFactory.classElement2('B', []);
1368 ConstructorElementImpl constructorB = 1376 ConstructorElementImpl constructorB =
1369 ElementFactory.constructorElement2(classB, '', []); 1377 ElementFactory.constructorElement2(classB, '', []);
1370 constructorB.setModifier(Modifier.SYNTHETIC, true); 1378 constructorB.setModifier(Modifier.SYNTHETIC, true);
1371 classB.constructors = [constructorB]; 1379 classB.constructors = [constructorB];
1372 ClassElement classM = ElementFactory.classElement2('M', []); 1380 ClassElement classM = ElementFactory.classElement2('M', []);
1373 WithClause withClause = 1381 WithClause withClause =
1374 AstFactory.withClause([AstFactory.typeName(classM, [])]); 1382 AstTestFactory.withClause([AstTestFactory.typeName(classM, [])]);
1375 ClassTypeAlias alias = AstFactory.classTypeAlias( 1383 ClassTypeAlias alias = AstTestFactory.classTypeAlias(
1376 'C', null, null, AstFactory.typeName(classB, []), withClause, null); 1384 'C', null, null, AstTestFactory.typeName(classB, []), withClause, null);
1377 1385
1378 ElementHolder holder = buildElementsForAst(alias); 1386 ElementHolder holder = buildElementsForAst(alias);
1379 List<ClassElement> types = holder.types; 1387 List<ClassElement> types = holder.types;
1380 expect(types, hasLength(1)); 1388 expect(types, hasLength(1));
1381 ClassElement type = types[0]; 1389 ClassElement type = types[0];
1382 expect(alias.element, same(type)); 1390 expect(alias.element, same(type));
1383 expect(type.name, equals('C')); 1391 expect(type.name, equals('C'));
1384 expect(type.isAbstract, isFalse); 1392 expect(type.isAbstract, isFalse);
1385 expect(type.isMixinApplication, isTrue); 1393 expect(type.isMixinApplication, isTrue);
1386 expect(type.isSynthetic, isFalse); 1394 expect(type.isSynthetic, isFalse);
1387 expect(type.typeParameters, isEmpty); 1395 expect(type.typeParameters, isEmpty);
1388 expect(type.fields, isEmpty); 1396 expect(type.fields, isEmpty);
1389 expect(type.methods, isEmpty); 1397 expect(type.methods, isEmpty);
1390 } 1398 }
1391 1399
1392 void test_visitClassTypeAlias_abstract() { 1400 void test_visitClassTypeAlias_abstract() {
1393 // class B {} 1401 // class B {}
1394 // class M {} 1402 // class M {}
1395 // abstract class C = B with M 1403 // abstract class C = B with M
1396 ClassElementImpl classB = ElementFactory.classElement2('B', []); 1404 ClassElementImpl classB = ElementFactory.classElement2('B', []);
1397 ConstructorElementImpl constructorB = 1405 ConstructorElementImpl constructorB =
1398 ElementFactory.constructorElement2(classB, '', []); 1406 ElementFactory.constructorElement2(classB, '', []);
1399 constructorB.setModifier(Modifier.SYNTHETIC, true); 1407 constructorB.setModifier(Modifier.SYNTHETIC, true);
1400 classB.constructors = [constructorB]; 1408 classB.constructors = [constructorB];
1401 ClassElement classM = ElementFactory.classElement2('M', []); 1409 ClassElement classM = ElementFactory.classElement2('M', []);
1402 WithClause withClause = 1410 WithClause withClause =
1403 AstFactory.withClause([AstFactory.typeName(classM, [])]); 1411 AstTestFactory.withClause([AstTestFactory.typeName(classM, [])]);
1404 ClassTypeAlias alias = AstFactory.classTypeAlias('C', null, 1412 ClassTypeAlias alias = AstTestFactory.classTypeAlias(
1405 Keyword.ABSTRACT, AstFactory.typeName(classB, []), withClause, null); 1413 'C',
1414 null,
1415 Keyword.ABSTRACT,
1416 AstTestFactory.typeName(classB, []),
1417 withClause,
1418 null);
1406 1419
1407 ElementHolder holder = buildElementsForAst(alias); 1420 ElementHolder holder = buildElementsForAst(alias);
1408 List<ClassElement> types = holder.types; 1421 List<ClassElement> types = holder.types;
1409 expect(types, hasLength(1)); 1422 expect(types, hasLength(1));
1410 ClassElement type = types[0]; 1423 ClassElement type = types[0];
1411 expect(type.isAbstract, isTrue); 1424 expect(type.isAbstract, isTrue);
1412 expect(type.isMixinApplication, isTrue); 1425 expect(type.isMixinApplication, isTrue);
1413 } 1426 }
1414 1427
1415 void test_visitClassTypeAlias_typeParams() { 1428 void test_visitClassTypeAlias_typeParams() {
1416 // class B {} 1429 // class B {}
1417 // class M {} 1430 // class M {}
1418 // class C<T> = B with M 1431 // class C<T> = B with M
1419 ClassElementImpl classB = ElementFactory.classElement2('B', []); 1432 ClassElementImpl classB = ElementFactory.classElement2('B', []);
1420 ConstructorElementImpl constructorB = 1433 ConstructorElementImpl constructorB =
1421 ElementFactory.constructorElement2(classB, '', []); 1434 ElementFactory.constructorElement2(classB, '', []);
1422 constructorB.setModifier(Modifier.SYNTHETIC, true); 1435 constructorB.setModifier(Modifier.SYNTHETIC, true);
1423 classB.constructors = [constructorB]; 1436 classB.constructors = [constructorB];
1424 ClassElementImpl classM = ElementFactory.classElement2('M', []); 1437 ClassElementImpl classM = ElementFactory.classElement2('M', []);
1425 WithClause withClause = 1438 WithClause withClause =
1426 AstFactory.withClause([AstFactory.typeName(classM, [])]); 1439 AstTestFactory.withClause([AstTestFactory.typeName(classM, [])]);
1427 ClassTypeAlias alias = AstFactory.classTypeAlias( 1440 ClassTypeAlias alias = AstTestFactory.classTypeAlias(
1428 'C', 1441 'C',
1429 AstFactory.typeParameterList(['T']), 1442 AstTestFactory.typeParameterList(['T']),
1430 null, 1443 null,
1431 AstFactory.typeName(classB, []), 1444 AstTestFactory.typeName(classB, []),
1432 withClause, 1445 withClause,
1433 null); 1446 null);
1434 1447
1435 ElementHolder holder = buildElementsForAst(alias); 1448 ElementHolder holder = buildElementsForAst(alias);
1436 List<ClassElement> types = holder.types; 1449 List<ClassElement> types = holder.types;
1437 expect(types, hasLength(1)); 1450 expect(types, hasLength(1));
1438 ClassElement type = types[0]; 1451 ClassElement type = types[0];
1439 expect(type.typeParameters, hasLength(1)); 1452 expect(type.typeParameters, hasLength(1));
1440 expect(type.typeParameters[0].name, equals('T')); 1453 expect(type.typeParameters[0].name, equals('T'));
1441 } 1454 }
1442 1455
1443 void test_visitConstructorDeclaration_external() { 1456 void test_visitConstructorDeclaration_external() {
1444 String className = "A"; 1457 String className = "A";
1445 ConstructorDeclaration constructorDeclaration = 1458 ConstructorDeclaration constructorDeclaration =
1446 AstFactory.constructorDeclaration2( 1459 AstTestFactory.constructorDeclaration2(
1447 null, 1460 null,
1448 null, 1461 null,
1449 AstFactory.identifier3(className), 1462 AstTestFactory.identifier3(className),
1450 null, 1463 null,
1451 AstFactory.formalParameterList(), 1464 AstTestFactory.formalParameterList(),
1452 null, 1465 null,
1453 AstFactory.blockFunctionBody2()); 1466 AstTestFactory.blockFunctionBody2());
1454 constructorDeclaration.externalKeyword = 1467 constructorDeclaration.externalKeyword =
1455 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); 1468 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL);
1456 1469
1457 ElementHolder holder = buildElementsForAst(constructorDeclaration); 1470 ElementHolder holder = buildElementsForAst(constructorDeclaration);
1458 List<ConstructorElement> constructors = holder.constructors; 1471 List<ConstructorElement> constructors = holder.constructors;
1459 expect(constructors, hasLength(1)); 1472 expect(constructors, hasLength(1));
1460 ConstructorElement constructor = constructors[0]; 1473 ConstructorElement constructor = constructors[0];
1461 expect(constructor, isNotNull); 1474 expect(constructor, isNotNull);
1462 expect(constructor.isExternal, isTrue); 1475 expect(constructor.isExternal, isTrue);
1463 expect(constructor.isFactory, isFalse); 1476 expect(constructor.isFactory, isFalse);
1464 expect(constructor.name, ""); 1477 expect(constructor.name, "");
1465 expect(constructor.functions, hasLength(0)); 1478 expect(constructor.functions, hasLength(0));
1466 expect(constructor.labels, hasLength(0)); 1479 expect(constructor.labels, hasLength(0));
1467 expect(constructor.localVariables, hasLength(0)); 1480 expect(constructor.localVariables, hasLength(0));
1468 expect(constructor.parameters, hasLength(0)); 1481 expect(constructor.parameters, hasLength(0));
1469 } 1482 }
1470 1483
1471 void test_visitConstructorDeclaration_factory() { 1484 void test_visitConstructorDeclaration_factory() {
1472 String className = "A"; 1485 String className = "A";
1473 ConstructorDeclaration constructorDeclaration = 1486 ConstructorDeclaration constructorDeclaration =
1474 AstFactory.constructorDeclaration2( 1487 AstTestFactory.constructorDeclaration2(
1475 null, 1488 null,
1476 Keyword.FACTORY, 1489 Keyword.FACTORY,
1477 AstFactory.identifier3(className), 1490 AstTestFactory.identifier3(className),
1478 null, 1491 null,
1479 AstFactory.formalParameterList(), 1492 AstTestFactory.formalParameterList(),
1480 null, 1493 null,
1481 AstFactory.blockFunctionBody2()); 1494 AstTestFactory.blockFunctionBody2());
1482 1495
1483 ElementHolder holder = buildElementsForAst(constructorDeclaration); 1496 ElementHolder holder = buildElementsForAst(constructorDeclaration);
1484 List<ConstructorElement> constructors = holder.constructors; 1497 List<ConstructorElement> constructors = holder.constructors;
1485 expect(constructors, hasLength(1)); 1498 expect(constructors, hasLength(1));
1486 ConstructorElement constructor = constructors[0]; 1499 ConstructorElement constructor = constructors[0];
1487 expect(constructor, isNotNull); 1500 expect(constructor, isNotNull);
1488 expect(constructor.isExternal, isFalse); 1501 expect(constructor.isExternal, isFalse);
1489 expect(constructor.isFactory, isTrue); 1502 expect(constructor.isFactory, isTrue);
1490 expect(constructor.name, ""); 1503 expect(constructor.name, "");
1491 expect(constructor.functions, hasLength(0)); 1504 expect(constructor.functions, hasLength(0));
1492 expect(constructor.labels, hasLength(0)); 1505 expect(constructor.labels, hasLength(0));
1493 expect(constructor.localVariables, hasLength(0)); 1506 expect(constructor.localVariables, hasLength(0));
1494 expect(constructor.parameters, hasLength(0)); 1507 expect(constructor.parameters, hasLength(0));
1495 } 1508 }
1496 1509
1497 void test_visitConstructorDeclaration_minimal() { 1510 void test_visitConstructorDeclaration_minimal() {
1498 String className = "A"; 1511 String className = "A";
1499 ConstructorDeclaration constructorDeclaration = 1512 ConstructorDeclaration constructorDeclaration =
1500 AstFactory.constructorDeclaration2( 1513 AstTestFactory.constructorDeclaration2(
1501 null, 1514 null,
1502 null, 1515 null,
1503 AstFactory.identifier3(className), 1516 AstTestFactory.identifier3(className),
1504 null, 1517 null,
1505 AstFactory.formalParameterList(), 1518 AstTestFactory.formalParameterList(),
1506 null, 1519 null,
1507 AstFactory.blockFunctionBody2()); 1520 AstTestFactory.blockFunctionBody2());
1508 constructorDeclaration.documentationComment = AstFactory 1521 constructorDeclaration.documentationComment = AstTestFactory
1509 .documentationComment( 1522 .documentationComment(
1510 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); 1523 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []);
1511 constructorDeclaration.endToken.offset = 80; 1524 constructorDeclaration.endToken.offset = 80;
1512 1525
1513 ElementHolder holder = buildElementsForAst(constructorDeclaration); 1526 ElementHolder holder = buildElementsForAst(constructorDeclaration);
1514 List<ConstructorElement> constructors = holder.constructors; 1527 List<ConstructorElement> constructors = holder.constructors;
1515 expect(constructors, hasLength(1)); 1528 expect(constructors, hasLength(1));
1516 ConstructorElement constructor = constructors[0]; 1529 ConstructorElement constructor = constructors[0];
1517 expect(constructor, isNotNull); 1530 expect(constructor, isNotNull);
1518 assertHasCodeRange(constructor, 50, 31); 1531 assertHasCodeRange(constructor, 50, 31);
1519 expect(constructor.documentationComment, '/// aaa'); 1532 expect(constructor.documentationComment, '/// aaa');
1520 expect(constructor.isExternal, isFalse); 1533 expect(constructor.isExternal, isFalse);
1521 expect(constructor.isFactory, isFalse); 1534 expect(constructor.isFactory, isFalse);
1522 expect(constructor.name, ""); 1535 expect(constructor.name, "");
1523 expect(constructor.functions, hasLength(0)); 1536 expect(constructor.functions, hasLength(0));
1524 expect(constructor.labels, hasLength(0)); 1537 expect(constructor.labels, hasLength(0));
1525 expect(constructor.localVariables, hasLength(0)); 1538 expect(constructor.localVariables, hasLength(0));
1526 expect(constructor.parameters, hasLength(0)); 1539 expect(constructor.parameters, hasLength(0));
1527 } 1540 }
1528 1541
1529 void test_visitConstructorDeclaration_named() { 1542 void test_visitConstructorDeclaration_named() {
1530 String className = "A"; 1543 String className = "A";
1531 String constructorName = "c"; 1544 String constructorName = "c";
1532 ConstructorDeclaration constructorDeclaration = 1545 ConstructorDeclaration constructorDeclaration =
1533 AstFactory.constructorDeclaration2( 1546 AstTestFactory.constructorDeclaration2(
1534 null, 1547 null,
1535 null, 1548 null,
1536 AstFactory.identifier3(className), 1549 AstTestFactory.identifier3(className),
1537 constructorName, 1550 constructorName,
1538 AstFactory.formalParameterList(), 1551 AstTestFactory.formalParameterList(),
1539 null, 1552 null,
1540 AstFactory.blockFunctionBody2()); 1553 AstTestFactory.blockFunctionBody2());
1541 1554
1542 ElementHolder holder = buildElementsForAst(constructorDeclaration); 1555 ElementHolder holder = buildElementsForAst(constructorDeclaration);
1543 List<ConstructorElement> constructors = holder.constructors; 1556 List<ConstructorElement> constructors = holder.constructors;
1544 expect(constructors, hasLength(1)); 1557 expect(constructors, hasLength(1));
1545 ConstructorElement constructor = constructors[0]; 1558 ConstructorElement constructor = constructors[0];
1546 expect(constructor, isNotNull); 1559 expect(constructor, isNotNull);
1547 expect(constructor.isExternal, isFalse); 1560 expect(constructor.isExternal, isFalse);
1548 expect(constructor.isFactory, isFalse); 1561 expect(constructor.isFactory, isFalse);
1549 expect(constructor.name, constructorName); 1562 expect(constructor.name, constructorName);
1550 expect(constructor.functions, hasLength(0)); 1563 expect(constructor.functions, hasLength(0));
1551 expect(constructor.labels, hasLength(0)); 1564 expect(constructor.labels, hasLength(0));
1552 expect(constructor.localVariables, hasLength(0)); 1565 expect(constructor.localVariables, hasLength(0));
1553 expect(constructor.parameters, hasLength(0)); 1566 expect(constructor.parameters, hasLength(0));
1554 expect(constructorDeclaration.name.staticElement, same(constructor)); 1567 expect(constructorDeclaration.name.staticElement, same(constructor));
1555 expect(constructorDeclaration.element, same(constructor)); 1568 expect(constructorDeclaration.element, same(constructor));
1556 } 1569 }
1557 1570
1558 void test_visitConstructorDeclaration_unnamed() { 1571 void test_visitConstructorDeclaration_unnamed() {
1559 String className = "A"; 1572 String className = "A";
1560 ConstructorDeclaration constructorDeclaration = 1573 ConstructorDeclaration constructorDeclaration =
1561 AstFactory.constructorDeclaration2( 1574 AstTestFactory.constructorDeclaration2(
1562 null, 1575 null,
1563 null, 1576 null,
1564 AstFactory.identifier3(className), 1577 AstTestFactory.identifier3(className),
1565 null, 1578 null,
1566 AstFactory.formalParameterList(), 1579 AstTestFactory.formalParameterList(),
1567 null, 1580 null,
1568 AstFactory.blockFunctionBody2()); 1581 AstTestFactory.blockFunctionBody2());
1569 1582
1570 ElementHolder holder = buildElementsForAst(constructorDeclaration); 1583 ElementHolder holder = buildElementsForAst(constructorDeclaration);
1571 List<ConstructorElement> constructors = holder.constructors; 1584 List<ConstructorElement> constructors = holder.constructors;
1572 expect(constructors, hasLength(1)); 1585 expect(constructors, hasLength(1));
1573 ConstructorElement constructor = constructors[0]; 1586 ConstructorElement constructor = constructors[0];
1574 expect(constructor, isNotNull); 1587 expect(constructor, isNotNull);
1575 expect(constructor.isExternal, isFalse); 1588 expect(constructor.isExternal, isFalse);
1576 expect(constructor.isFactory, isFalse); 1589 expect(constructor.isFactory, isFalse);
1577 expect(constructor.name, ""); 1590 expect(constructor.name, "");
1578 expect(constructor.functions, hasLength(0)); 1591 expect(constructor.functions, hasLength(0));
1579 expect(constructor.labels, hasLength(0)); 1592 expect(constructor.labels, hasLength(0));
1580 expect(constructor.localVariables, hasLength(0)); 1593 expect(constructor.localVariables, hasLength(0));
1581 expect(constructor.parameters, hasLength(0)); 1594 expect(constructor.parameters, hasLength(0));
1582 expect(constructorDeclaration.element, same(constructor)); 1595 expect(constructorDeclaration.element, same(constructor));
1583 } 1596 }
1584 1597
1585 void test_visitEnumDeclaration() { 1598 void test_visitEnumDeclaration() {
1586 String enumName = "E"; 1599 String enumName = "E";
1587 EnumDeclaration enumDeclaration = 1600 EnumDeclaration enumDeclaration =
1588 AstFactory.enumDeclaration2(enumName, ["ONE"]); 1601 AstTestFactory.enumDeclaration2(enumName, ["ONE"]);
1589 enumDeclaration.documentationComment = AstFactory.documentationComment( 1602 enumDeclaration.documentationComment = AstTestFactory.documentationComment(
1590 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); 1603 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []);
1591 enumDeclaration.endToken.offset = 80; 1604 enumDeclaration.endToken.offset = 80;
1592 ElementHolder holder = buildElementsForAst(enumDeclaration); 1605 ElementHolder holder = buildElementsForAst(enumDeclaration);
1593 List<ClassElement> enums = holder.enums; 1606 List<ClassElement> enums = holder.enums;
1594 expect(enums, hasLength(1)); 1607 expect(enums, hasLength(1));
1595 ClassElement enumElement = enums[0]; 1608 ClassElement enumElement = enums[0];
1596 expect(enumElement, isNotNull); 1609 expect(enumElement, isNotNull);
1597 assertHasCodeRange(enumElement, 50, 31); 1610 assertHasCodeRange(enumElement, 50, 31);
1598 expect(enumElement.documentationComment, '/// aaa'); 1611 expect(enumElement.documentationComment, '/// aaa');
1599 expect(enumElement.name, enumName); 1612 expect(enumElement.name, enumName);
1600 } 1613 }
1601 1614
1602 void test_visitFieldDeclaration() { 1615 void test_visitFieldDeclaration() {
1603 String firstFieldName = "x"; 1616 String firstFieldName = "x";
1604 String secondFieldName = "y"; 1617 String secondFieldName = "y";
1605 FieldDeclaration fieldDeclaration = 1618 FieldDeclaration fieldDeclaration =
1606 AstFactory.fieldDeclaration2(false, null, [ 1619 AstTestFactory.fieldDeclaration2(false, null, [
1607 AstFactory.variableDeclaration(firstFieldName), 1620 AstTestFactory.variableDeclaration(firstFieldName),
1608 AstFactory.variableDeclaration(secondFieldName) 1621 AstTestFactory.variableDeclaration(secondFieldName)
1609 ]); 1622 ]);
1610 fieldDeclaration.documentationComment = AstFactory.documentationComment( 1623 fieldDeclaration.documentationComment = AstTestFactory.documentationComment(
1611 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); 1624 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []);
1612 fieldDeclaration.endToken.offset = 110; 1625 fieldDeclaration.endToken.offset = 110;
1613 1626
1614 ElementHolder holder = buildElementsForAst(fieldDeclaration); 1627 ElementHolder holder = buildElementsForAst(fieldDeclaration);
1615 List<FieldElement> fields = holder.fields; 1628 List<FieldElement> fields = holder.fields;
1616 expect(fields, hasLength(2)); 1629 expect(fields, hasLength(2));
1617 1630
1618 FieldElement firstField = fields[0]; 1631 FieldElement firstField = fields[0];
1619 expect(firstField, isNotNull); 1632 expect(firstField, isNotNull);
1620 assertHasCodeRange(firstField, 50, 61); 1633 assertHasCodeRange(firstField, 50, 61);
(...skipping 11 matching lines...) Expand all
1632 expect(secondField.name, secondFieldName); 1645 expect(secondField.name, secondFieldName);
1633 expect(secondField.initializer, isNull); 1646 expect(secondField.initializer, isNull);
1634 expect(secondField.isConst, isFalse); 1647 expect(secondField.isConst, isFalse);
1635 expect(secondField.isFinal, isFalse); 1648 expect(secondField.isFinal, isFalse);
1636 expect(secondField.isSynthetic, isFalse); 1649 expect(secondField.isSynthetic, isFalse);
1637 } 1650 }
1638 1651
1639 void test_visitFieldFormalParameter() { 1652 void test_visitFieldFormalParameter() {
1640 String parameterName = "p"; 1653 String parameterName = "p";
1641 FieldFormalParameter formalParameter = 1654 FieldFormalParameter formalParameter =
1642 AstFactory.fieldFormalParameter(null, null, parameterName); 1655 AstTestFactory.fieldFormalParameter(null, null, parameterName);
1643 formalParameter.beginToken.offset = 50; 1656 formalParameter.beginToken.offset = 50;
1644 formalParameter.endToken.offset = 80; 1657 formalParameter.endToken.offset = 80;
1645 ElementHolder holder = buildElementsForAst(formalParameter); 1658 ElementHolder holder = buildElementsForAst(formalParameter);
1646 List<ParameterElement> parameters = holder.parameters; 1659 List<ParameterElement> parameters = holder.parameters;
1647 expect(parameters, hasLength(1)); 1660 expect(parameters, hasLength(1));
1648 ParameterElement parameter = parameters[0]; 1661 ParameterElement parameter = parameters[0];
1649 expect(parameter, isNotNull); 1662 expect(parameter, isNotNull);
1650 assertHasCodeRange(parameter, 50, 31); 1663 assertHasCodeRange(parameter, 50, 31);
1651 expect(parameter.name, parameterName); 1664 expect(parameter.name, parameterName);
1652 expect(parameter.initializer, isNull); 1665 expect(parameter.initializer, isNull);
1653 expect(parameter.isConst, isFalse); 1666 expect(parameter.isConst, isFalse);
1654 expect(parameter.isFinal, isFalse); 1667 expect(parameter.isFinal, isFalse);
1655 expect(parameter.isSynthetic, isFalse); 1668 expect(parameter.isSynthetic, isFalse);
1656 expect(parameter.parameterKind, ParameterKind.REQUIRED); 1669 expect(parameter.parameterKind, ParameterKind.REQUIRED);
1657 expect(parameter.parameters, hasLength(0)); 1670 expect(parameter.parameters, hasLength(0));
1658 } 1671 }
1659 1672
1660 void test_visitFieldFormalParameter_functionTyped() { 1673 void test_visitFieldFormalParameter_functionTyped() {
1661 String parameterName = "p"; 1674 String parameterName = "p";
1662 FieldFormalParameter formalParameter = AstFactory.fieldFormalParameter( 1675 FieldFormalParameter formalParameter = AstTestFactory.fieldFormalParameter(
1663 null, 1676 null,
1664 null, 1677 null,
1665 parameterName, 1678 parameterName,
1666 AstFactory 1679 AstTestFactory
1667 .formalParameterList([AstFactory.simpleFormalParameter3("a")])); 1680 .formalParameterList([AstTestFactory.simpleFormalParameter3("a")]));
1668 ElementHolder holder = buildElementsForAst(formalParameter); 1681 ElementHolder holder = buildElementsForAst(formalParameter);
1669 List<ParameterElement> parameters = holder.parameters; 1682 List<ParameterElement> parameters = holder.parameters;
1670 expect(parameters, hasLength(1)); 1683 expect(parameters, hasLength(1));
1671 ParameterElement parameter = parameters[0]; 1684 ParameterElement parameter = parameters[0];
1672 expect(parameter, isNotNull); 1685 expect(parameter, isNotNull);
1673 expect(parameter.name, parameterName); 1686 expect(parameter.name, parameterName);
1674 expect(parameter.initializer, isNull); 1687 expect(parameter.initializer, isNull);
1675 expect(parameter.isConst, isFalse); 1688 expect(parameter.isConst, isFalse);
1676 expect(parameter.isFinal, isFalse); 1689 expect(parameter.isFinal, isFalse);
1677 expect(parameter.isSynthetic, isFalse); 1690 expect(parameter.isSynthetic, isFalse);
1678 expect(parameter.parameterKind, ParameterKind.REQUIRED); 1691 expect(parameter.parameterKind, ParameterKind.REQUIRED);
1679 expect(parameter.parameters, hasLength(1)); 1692 expect(parameter.parameters, hasLength(1));
1680 } 1693 }
1681 1694
1682 void test_visitFormalParameterList() { 1695 void test_visitFormalParameterList() {
1683 String firstParameterName = "a"; 1696 String firstParameterName = "a";
1684 String secondParameterName = "b"; 1697 String secondParameterName = "b";
1685 FormalParameterList parameterList = AstFactory.formalParameterList([ 1698 FormalParameterList parameterList = AstTestFactory.formalParameterList([
1686 AstFactory.simpleFormalParameter3(firstParameterName), 1699 AstTestFactory.simpleFormalParameter3(firstParameterName),
1687 AstFactory.simpleFormalParameter3(secondParameterName) 1700 AstTestFactory.simpleFormalParameter3(secondParameterName)
1688 ]); 1701 ]);
1689 ElementHolder holder = buildElementsForAst(parameterList); 1702 ElementHolder holder = buildElementsForAst(parameterList);
1690 List<ParameterElement> parameters = holder.parameters; 1703 List<ParameterElement> parameters = holder.parameters;
1691 expect(parameters, hasLength(2)); 1704 expect(parameters, hasLength(2));
1692 expect(parameters[0].name, firstParameterName); 1705 expect(parameters[0].name, firstParameterName);
1693 expect(parameters[1].name, secondParameterName); 1706 expect(parameters[1].name, secondParameterName);
1694 } 1707 }
1695 1708
1696 void test_visitFunctionDeclaration_external() { 1709 void test_visitFunctionDeclaration_external() {
1697 // external f(); 1710 // external f();
1698 String functionName = "f"; 1711 String functionName = "f";
1699 FunctionDeclaration declaration = AstFactory.functionDeclaration( 1712 FunctionDeclaration declaration = AstTestFactory.functionDeclaration(
1700 null, 1713 null,
1701 null, 1714 null,
1702 functionName, 1715 functionName,
1703 AstFactory.functionExpression2( 1716 AstTestFactory.functionExpression2(AstTestFactory.formalParameterList(),
1704 AstFactory.formalParameterList(), AstFactory.emptyFunctionBody())); 1717 AstTestFactory.emptyFunctionBody()));
1705 declaration.externalKeyword = 1718 declaration.externalKeyword =
1706 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); 1719 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL);
1707 1720
1708 ElementHolder holder = buildElementsForAst(declaration); 1721 ElementHolder holder = buildElementsForAst(declaration);
1709 List<FunctionElement> functions = holder.functions; 1722 List<FunctionElement> functions = holder.functions;
1710 expect(functions, hasLength(1)); 1723 expect(functions, hasLength(1));
1711 FunctionElement function = functions[0]; 1724 FunctionElement function = functions[0];
1712 expect(function, isNotNull); 1725 expect(function, isNotNull);
1713 expect(function.name, functionName); 1726 expect(function.name, functionName);
1714 expect(declaration.element, same(function)); 1727 expect(declaration.element, same(function));
1715 expect(declaration.functionExpression.element, same(function)); 1728 expect(declaration.functionExpression.element, same(function));
1716 expect(function.hasImplicitReturnType, isTrue); 1729 expect(function.hasImplicitReturnType, isTrue);
1717 expect(function.isExternal, isTrue); 1730 expect(function.isExternal, isTrue);
1718 expect(function.isSynthetic, isFalse); 1731 expect(function.isSynthetic, isFalse);
1719 expect(function.typeParameters, hasLength(0)); 1732 expect(function.typeParameters, hasLength(0));
1720 } 1733 }
1721 1734
1722 void test_visitFunctionDeclaration_getter() { 1735 void test_visitFunctionDeclaration_getter() {
1723 // get f() {} 1736 // get f() {}
1724 String functionName = "f"; 1737 String functionName = "f";
1725 FunctionDeclaration declaration = AstFactory.functionDeclaration( 1738 FunctionDeclaration declaration = AstTestFactory.functionDeclaration(
1726 null, 1739 null,
1727 Keyword.GET, 1740 Keyword.GET,
1728 functionName, 1741 functionName,
1729 AstFactory.functionExpression2( 1742 AstTestFactory.functionExpression2(AstTestFactory.formalParameterList(),
1730 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2())); 1743 AstTestFactory.blockFunctionBody2()));
1731 declaration.documentationComment = AstFactory.documentationComment( 1744 declaration.documentationComment = AstTestFactory.documentationComment(
1732 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); 1745 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []);
1733 declaration.endToken.offset = 80; 1746 declaration.endToken.offset = 80;
1734 1747
1735 ElementHolder holder = buildElementsForAst(declaration); 1748 ElementHolder holder = buildElementsForAst(declaration);
1736 List<PropertyAccessorElement> accessors = holder.accessors; 1749 List<PropertyAccessorElement> accessors = holder.accessors;
1737 expect(accessors, hasLength(1)); 1750 expect(accessors, hasLength(1));
1738 PropertyAccessorElement accessor = accessors[0]; 1751 PropertyAccessorElement accessor = accessors[0];
1739 expect(accessor, isNotNull); 1752 expect(accessor, isNotNull);
1740 assertHasCodeRange(accessor, 50, 31); 1753 assertHasCodeRange(accessor, 50, 31);
1741 expect(accessor.documentationComment, '/// aaa'); 1754 expect(accessor.documentationComment, '/// aaa');
1742 expect(accessor.name, functionName); 1755 expect(accessor.name, functionName);
1743 expect(declaration.element, same(accessor)); 1756 expect(declaration.element, same(accessor));
1744 expect(declaration.functionExpression.element, same(accessor)); 1757 expect(declaration.functionExpression.element, same(accessor));
1745 expect(accessor.hasImplicitReturnType, isTrue); 1758 expect(accessor.hasImplicitReturnType, isTrue);
1746 expect(accessor.isGetter, isTrue); 1759 expect(accessor.isGetter, isTrue);
1747 expect(accessor.isExternal, isFalse); 1760 expect(accessor.isExternal, isFalse);
1748 expect(accessor.isSetter, isFalse); 1761 expect(accessor.isSetter, isFalse);
1749 expect(accessor.isSynthetic, isFalse); 1762 expect(accessor.isSynthetic, isFalse);
1750 expect(accessor.typeParameters, hasLength(0)); 1763 expect(accessor.typeParameters, hasLength(0));
1751 PropertyInducingElement variable = accessor.variable; 1764 PropertyInducingElement variable = accessor.variable;
1752 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableElement, 1765 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableElement,
1753 TopLevelVariableElement, variable); 1766 TopLevelVariableElement, variable);
1754 expect(variable.isSynthetic, isTrue); 1767 expect(variable.isSynthetic, isTrue);
1755 } 1768 }
1756 1769
1757 void test_visitFunctionDeclaration_plain() { 1770 void test_visitFunctionDeclaration_plain() {
1758 // T f() {} 1771 // T f() {}
1759 String functionName = "f"; 1772 String functionName = "f";
1760 FunctionDeclaration declaration = AstFactory.functionDeclaration( 1773 FunctionDeclaration declaration = AstTestFactory.functionDeclaration(
1761 AstFactory.typeName4('T'), 1774 AstTestFactory.typeName4('T'),
1762 null, 1775 null,
1763 functionName, 1776 functionName,
1764 AstFactory.functionExpression2( 1777 AstTestFactory.functionExpression2(AstTestFactory.formalParameterList(),
1765 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2())); 1778 AstTestFactory.blockFunctionBody2()));
1766 declaration.documentationComment = AstFactory.documentationComment( 1779 declaration.documentationComment = AstTestFactory.documentationComment(
1767 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); 1780 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []);
1768 declaration.endToken.offset = 80; 1781 declaration.endToken.offset = 80;
1769 1782
1770 ElementHolder holder = buildElementsForAst(declaration); 1783 ElementHolder holder = buildElementsForAst(declaration);
1771 List<FunctionElement> functions = holder.functions; 1784 List<FunctionElement> functions = holder.functions;
1772 expect(functions, hasLength(1)); 1785 expect(functions, hasLength(1));
1773 FunctionElement function = functions[0]; 1786 FunctionElement function = functions[0];
1774 expect(function, isNotNull); 1787 expect(function, isNotNull);
1775 assertHasCodeRange(function, 50, 31); 1788 assertHasCodeRange(function, 50, 31);
1776 expect(function.documentationComment, '/// aaa'); 1789 expect(function.documentationComment, '/// aaa');
1777 expect(function.hasImplicitReturnType, isFalse); 1790 expect(function.hasImplicitReturnType, isFalse);
1778 expect(function.name, functionName); 1791 expect(function.name, functionName);
1779 expect(declaration.element, same(function)); 1792 expect(declaration.element, same(function));
1780 expect(declaration.functionExpression.element, same(function)); 1793 expect(declaration.functionExpression.element, same(function));
1781 expect(function.isExternal, isFalse); 1794 expect(function.isExternal, isFalse);
1782 expect(function.isSynthetic, isFalse); 1795 expect(function.isSynthetic, isFalse);
1783 expect(function.typeParameters, hasLength(0)); 1796 expect(function.typeParameters, hasLength(0));
1784 } 1797 }
1785 1798
1786 void test_visitFunctionDeclaration_setter() { 1799 void test_visitFunctionDeclaration_setter() {
1787 // set f() {} 1800 // set f() {}
1788 String functionName = "f"; 1801 String functionName = "f";
1789 FunctionDeclaration declaration = AstFactory.functionDeclaration( 1802 FunctionDeclaration declaration = AstTestFactory.functionDeclaration(
1790 null, 1803 null,
1791 Keyword.SET, 1804 Keyword.SET,
1792 functionName, 1805 functionName,
1793 AstFactory.functionExpression2( 1806 AstTestFactory.functionExpression2(AstTestFactory.formalParameterList(),
1794 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2())); 1807 AstTestFactory.blockFunctionBody2()));
1795 declaration.documentationComment = AstFactory.documentationComment( 1808 declaration.documentationComment = AstTestFactory.documentationComment(
1796 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); 1809 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []);
1797 declaration.endToken.offset = 80; 1810 declaration.endToken.offset = 80;
1798 1811
1799 ElementHolder holder = buildElementsForAst(declaration); 1812 ElementHolder holder = buildElementsForAst(declaration);
1800 List<PropertyAccessorElement> accessors = holder.accessors; 1813 List<PropertyAccessorElement> accessors = holder.accessors;
1801 expect(accessors, hasLength(1)); 1814 expect(accessors, hasLength(1));
1802 PropertyAccessorElement accessor = accessors[0]; 1815 PropertyAccessorElement accessor = accessors[0];
1803 expect(accessor, isNotNull); 1816 expect(accessor, isNotNull);
1804 assertHasCodeRange(accessor, 50, 31); 1817 assertHasCodeRange(accessor, 50, 31);
1805 expect(accessor.documentationComment, '/// aaa'); 1818 expect(accessor.documentationComment, '/// aaa');
1806 expect(accessor.hasImplicitReturnType, isTrue); 1819 expect(accessor.hasImplicitReturnType, isTrue);
1807 expect(accessor.name, "$functionName="); 1820 expect(accessor.name, "$functionName=");
1808 expect(declaration.element, same(accessor)); 1821 expect(declaration.element, same(accessor));
1809 expect(declaration.functionExpression.element, same(accessor)); 1822 expect(declaration.functionExpression.element, same(accessor));
1810 expect(accessor.isGetter, isFalse); 1823 expect(accessor.isGetter, isFalse);
1811 expect(accessor.isExternal, isFalse); 1824 expect(accessor.isExternal, isFalse);
1812 expect(accessor.isSetter, isTrue); 1825 expect(accessor.isSetter, isTrue);
1813 expect(accessor.isSynthetic, isFalse); 1826 expect(accessor.isSynthetic, isFalse);
1814 expect(accessor.typeParameters, hasLength(0)); 1827 expect(accessor.typeParameters, hasLength(0));
1815 PropertyInducingElement variable = accessor.variable; 1828 PropertyInducingElement variable = accessor.variable;
1816 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableElement, 1829 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableElement,
1817 TopLevelVariableElement, variable); 1830 TopLevelVariableElement, variable);
1818 expect(variable.isSynthetic, isTrue); 1831 expect(variable.isSynthetic, isTrue);
1819 } 1832 }
1820 1833
1821 void test_visitFunctionDeclaration_typeParameters() { 1834 void test_visitFunctionDeclaration_typeParameters() {
1822 // f<E>() {} 1835 // f<E>() {}
1823 String functionName = 'f'; 1836 String functionName = 'f';
1824 String typeParameterName = 'E'; 1837 String typeParameterName = 'E';
1825 FunctionExpression expression = AstFactory.functionExpression3( 1838 FunctionExpression expression = AstTestFactory.functionExpression3(
1826 AstFactory.typeParameterList([typeParameterName]), 1839 AstTestFactory.typeParameterList([typeParameterName]),
1827 AstFactory.formalParameterList(), 1840 AstTestFactory.formalParameterList(),
1828 AstFactory.blockFunctionBody2()); 1841 AstTestFactory.blockFunctionBody2());
1829 FunctionDeclaration declaration = 1842 FunctionDeclaration declaration = AstTestFactory.functionDeclaration(
1830 AstFactory.functionDeclaration(null, null, functionName, expression); 1843 null, null, functionName, expression);
1831 1844
1832 ElementHolder holder = buildElementsForAst(declaration); 1845 ElementHolder holder = buildElementsForAst(declaration);
1833 List<FunctionElement> functions = holder.functions; 1846 List<FunctionElement> functions = holder.functions;
1834 expect(functions, hasLength(1)); 1847 expect(functions, hasLength(1));
1835 FunctionElement function = functions[0]; 1848 FunctionElement function = functions[0];
1836 expect(function, isNotNull); 1849 expect(function, isNotNull);
1837 expect(function.hasImplicitReturnType, isTrue); 1850 expect(function.hasImplicitReturnType, isTrue);
1838 expect(function.name, functionName); 1851 expect(function.name, functionName);
1839 expect(function.isExternal, isFalse); 1852 expect(function.isExternal, isFalse);
1840 expect(function.isSynthetic, isFalse); 1853 expect(function.isSynthetic, isFalse);
1841 expect(declaration.element, same(function)); 1854 expect(declaration.element, same(function));
1842 expect(expression.element, same(function)); 1855 expect(expression.element, same(function));
1843 List<TypeParameterElement> typeParameters = function.typeParameters; 1856 List<TypeParameterElement> typeParameters = function.typeParameters;
1844 expect(typeParameters, hasLength(1)); 1857 expect(typeParameters, hasLength(1));
1845 TypeParameterElement typeParameter = typeParameters[0]; 1858 TypeParameterElement typeParameter = typeParameters[0];
1846 expect(typeParameter, isNotNull); 1859 expect(typeParameter, isNotNull);
1847 expect(typeParameter.name, typeParameterName); 1860 expect(typeParameter.name, typeParameterName);
1848 } 1861 }
1849 1862
1850 void test_visitMethodDeclaration_abstract() { 1863 void test_visitMethodDeclaration_abstract() {
1851 // m(); 1864 // m();
1852 String methodName = "m"; 1865 String methodName = "m";
1853 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( 1866 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2(
1854 null, 1867 null,
1855 null, 1868 null,
1856 null, 1869 null,
1857 null, 1870 null,
1858 AstFactory.identifier3(methodName), 1871 AstTestFactory.identifier3(methodName),
1859 AstFactory.formalParameterList(), 1872 AstTestFactory.formalParameterList(),
1860 AstFactory.emptyFunctionBody()); 1873 AstTestFactory.emptyFunctionBody());
1861 1874
1862 ElementHolder holder = buildElementsForAst(methodDeclaration); 1875 ElementHolder holder = buildElementsForAst(methodDeclaration);
1863 List<MethodElement> methods = holder.methods; 1876 List<MethodElement> methods = holder.methods;
1864 expect(methods, hasLength(1)); 1877 expect(methods, hasLength(1));
1865 MethodElement method = methods[0]; 1878 MethodElement method = methods[0];
1866 expect(method, isNotNull); 1879 expect(method, isNotNull);
1867 expect(method.hasImplicitReturnType, isTrue); 1880 expect(method.hasImplicitReturnType, isTrue);
1868 expect(method.name, methodName); 1881 expect(method.name, methodName);
1869 expect(method.functions, hasLength(0)); 1882 expect(method.functions, hasLength(0));
1870 expect(method.labels, hasLength(0)); 1883 expect(method.labels, hasLength(0));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1910 FieldDeclaration fieldDeclNode = classNode.members[0]; 1923 FieldDeclaration fieldDeclNode = classNode.members[0];
1911 VariableDeclaration fieldNode = fieldDeclNode.fields.variables.single; 1924 VariableDeclaration fieldNode = fieldDeclNode.fields.variables.single;
1912 MethodDeclaration getterNode = classNode.members[1]; 1925 MethodDeclaration getterNode = classNode.members[1];
1913 expect(fieldNode.element, notSyntheticFieldElement); 1926 expect(fieldNode.element, notSyntheticFieldElement);
1914 expect(getterNode.element, notSyntheticGetterElement); 1927 expect(getterNode.element, notSyntheticGetterElement);
1915 } 1928 }
1916 1929
1917 void test_visitMethodDeclaration_external() { 1930 void test_visitMethodDeclaration_external() {
1918 // external m(); 1931 // external m();
1919 String methodName = "m"; 1932 String methodName = "m";
1920 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( 1933 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2(
1921 null, 1934 null,
1922 null, 1935 null,
1923 null, 1936 null,
1924 null, 1937 null,
1925 AstFactory.identifier3(methodName), 1938 AstTestFactory.identifier3(methodName),
1926 AstFactory.formalParameterList(), 1939 AstTestFactory.formalParameterList(),
1927 AstFactory.emptyFunctionBody()); 1940 AstTestFactory.emptyFunctionBody());
1928 methodDeclaration.externalKeyword = 1941 methodDeclaration.externalKeyword =
1929 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); 1942 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL);
1930 1943
1931 ElementHolder holder = buildElementsForAst(methodDeclaration); 1944 ElementHolder holder = buildElementsForAst(methodDeclaration);
1932 List<MethodElement> methods = holder.methods; 1945 List<MethodElement> methods = holder.methods;
1933 expect(methods, hasLength(1)); 1946 expect(methods, hasLength(1));
1934 MethodElement method = methods[0]; 1947 MethodElement method = methods[0];
1935 expect(method, isNotNull); 1948 expect(method, isNotNull);
1936 expect(method.hasImplicitReturnType, isTrue); 1949 expect(method.hasImplicitReturnType, isTrue);
1937 expect(method.name, methodName); 1950 expect(method.name, methodName);
1938 expect(method.functions, hasLength(0)); 1951 expect(method.functions, hasLength(0));
1939 expect(method.labels, hasLength(0)); 1952 expect(method.labels, hasLength(0));
1940 expect(method.localVariables, hasLength(0)); 1953 expect(method.localVariables, hasLength(0));
1941 expect(method.parameters, hasLength(0)); 1954 expect(method.parameters, hasLength(0));
1942 expect(method.typeParameters, hasLength(0)); 1955 expect(method.typeParameters, hasLength(0));
1943 expect(method.isAbstract, isFalse); 1956 expect(method.isAbstract, isFalse);
1944 expect(method.isExternal, isTrue); 1957 expect(method.isExternal, isTrue);
1945 expect(method.isStatic, isFalse); 1958 expect(method.isStatic, isFalse);
1946 expect(method.isSynthetic, isFalse); 1959 expect(method.isSynthetic, isFalse);
1947 } 1960 }
1948 1961
1949 void test_visitMethodDeclaration_getter() { 1962 void test_visitMethodDeclaration_getter() {
1950 // get m() {} 1963 // get m() {}
1951 String methodName = "m"; 1964 String methodName = "m";
1952 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( 1965 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2(
1953 null, 1966 null,
1954 null, 1967 null,
1955 Keyword.GET, 1968 Keyword.GET,
1956 null, 1969 null,
1957 AstFactory.identifier3(methodName), 1970 AstTestFactory.identifier3(methodName),
1958 AstFactory.formalParameterList(), 1971 AstTestFactory.formalParameterList(),
1959 AstFactory.blockFunctionBody2()); 1972 AstTestFactory.blockFunctionBody2());
1960 methodDeclaration.documentationComment = AstFactory.documentationComment( 1973 methodDeclaration.documentationComment = AstTestFactory
1961 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); 1974 .documentationComment(
1975 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []);
1962 methodDeclaration.endToken.offset = 80; 1976 methodDeclaration.endToken.offset = 80;
1963 1977
1964 ElementHolder holder = buildElementsForAst(methodDeclaration); 1978 ElementHolder holder = buildElementsForAst(methodDeclaration);
1965 List<FieldElement> fields = holder.fields; 1979 List<FieldElement> fields = holder.fields;
1966 expect(fields, hasLength(1)); 1980 expect(fields, hasLength(1));
1967 FieldElement field = fields[0]; 1981 FieldElement field = fields[0];
1968 expect(field, isNotNull); 1982 expect(field, isNotNull);
1969 expect(field.name, methodName); 1983 expect(field.name, methodName);
1970 expect(field.isSynthetic, isTrue); 1984 expect(field.isSynthetic, isTrue);
1971 expect(field.setter, isNull); 1985 expect(field.setter, isNull);
(...skipping 10 matching lines...) Expand all
1982 expect(getter.variable, field); 1996 expect(getter.variable, field);
1983 expect(getter.functions, hasLength(0)); 1997 expect(getter.functions, hasLength(0));
1984 expect(getter.labels, hasLength(0)); 1998 expect(getter.labels, hasLength(0));
1985 expect(getter.localVariables, hasLength(0)); 1999 expect(getter.localVariables, hasLength(0));
1986 expect(getter.parameters, hasLength(0)); 2000 expect(getter.parameters, hasLength(0));
1987 } 2001 }
1988 2002
1989 void test_visitMethodDeclaration_getter_abstract() { 2003 void test_visitMethodDeclaration_getter_abstract() {
1990 // get m(); 2004 // get m();
1991 String methodName = "m"; 2005 String methodName = "m";
1992 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( 2006 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2(
1993 null, 2007 null,
1994 null, 2008 null,
1995 Keyword.GET, 2009 Keyword.GET,
1996 null, 2010 null,
1997 AstFactory.identifier3(methodName), 2011 AstTestFactory.identifier3(methodName),
1998 AstFactory.formalParameterList(), 2012 AstTestFactory.formalParameterList(),
1999 AstFactory.emptyFunctionBody()); 2013 AstTestFactory.emptyFunctionBody());
2000 2014
2001 ElementHolder holder = buildElementsForAst(methodDeclaration); 2015 ElementHolder holder = buildElementsForAst(methodDeclaration);
2002 List<FieldElement> fields = holder.fields; 2016 List<FieldElement> fields = holder.fields;
2003 expect(fields, hasLength(1)); 2017 expect(fields, hasLength(1));
2004 FieldElement field = fields[0]; 2018 FieldElement field = fields[0];
2005 expect(field, isNotNull); 2019 expect(field, isNotNull);
2006 expect(field.name, methodName); 2020 expect(field.name, methodName);
2007 expect(field.isSynthetic, isTrue); 2021 expect(field.isSynthetic, isTrue);
2008 expect(field.setter, isNull); 2022 expect(field.setter, isNull);
2009 PropertyAccessorElement getter = field.getter; 2023 PropertyAccessorElement getter = field.getter;
2010 expect(getter, isNotNull); 2024 expect(getter, isNotNull);
2011 expect(getter.hasImplicitReturnType, isTrue); 2025 expect(getter.hasImplicitReturnType, isTrue);
2012 expect(getter.isAbstract, isTrue); 2026 expect(getter.isAbstract, isTrue);
2013 expect(getter.isExternal, isFalse); 2027 expect(getter.isExternal, isFalse);
2014 expect(getter.isGetter, isTrue); 2028 expect(getter.isGetter, isTrue);
2015 expect(getter.isSynthetic, isFalse); 2029 expect(getter.isSynthetic, isFalse);
2016 expect(getter.name, methodName); 2030 expect(getter.name, methodName);
2017 expect(getter.variable, field); 2031 expect(getter.variable, field);
2018 expect(getter.functions, hasLength(0)); 2032 expect(getter.functions, hasLength(0));
2019 expect(getter.labels, hasLength(0)); 2033 expect(getter.labels, hasLength(0));
2020 expect(getter.localVariables, hasLength(0)); 2034 expect(getter.localVariables, hasLength(0));
2021 expect(getter.parameters, hasLength(0)); 2035 expect(getter.parameters, hasLength(0));
2022 } 2036 }
2023 2037
2024 void test_visitMethodDeclaration_getter_external() { 2038 void test_visitMethodDeclaration_getter_external() {
2025 // external get m(); 2039 // external get m();
2026 String methodName = "m"; 2040 String methodName = "m";
2027 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration( 2041 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration(
2028 null, 2042 null,
2029 null, 2043 null,
2030 Keyword.GET, 2044 Keyword.GET,
2031 null, 2045 null,
2032 AstFactory.identifier3(methodName), 2046 AstTestFactory.identifier3(methodName),
2033 AstFactory.formalParameterList()); 2047 AstTestFactory.formalParameterList());
2034 methodDeclaration.externalKeyword = 2048 methodDeclaration.externalKeyword =
2035 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); 2049 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL);
2036 2050
2037 ElementHolder holder = buildElementsForAst(methodDeclaration); 2051 ElementHolder holder = buildElementsForAst(methodDeclaration);
2038 List<FieldElement> fields = holder.fields; 2052 List<FieldElement> fields = holder.fields;
2039 expect(fields, hasLength(1)); 2053 expect(fields, hasLength(1));
2040 FieldElement field = fields[0]; 2054 FieldElement field = fields[0];
2041 expect(field, isNotNull); 2055 expect(field, isNotNull);
2042 expect(field.name, methodName); 2056 expect(field.name, methodName);
2043 expect(field.isSynthetic, isTrue); 2057 expect(field.isSynthetic, isTrue);
2044 expect(field.setter, isNull); 2058 expect(field.setter, isNull);
2045 PropertyAccessorElement getter = field.getter; 2059 PropertyAccessorElement getter = field.getter;
2046 expect(getter, isNotNull); 2060 expect(getter, isNotNull);
2047 expect(getter.hasImplicitReturnType, isTrue); 2061 expect(getter.hasImplicitReturnType, isTrue);
2048 expect(getter.isAbstract, isFalse); 2062 expect(getter.isAbstract, isFalse);
2049 expect(getter.isExternal, isTrue); 2063 expect(getter.isExternal, isTrue);
2050 expect(getter.isGetter, isTrue); 2064 expect(getter.isGetter, isTrue);
2051 expect(getter.isSynthetic, isFalse); 2065 expect(getter.isSynthetic, isFalse);
2052 expect(getter.name, methodName); 2066 expect(getter.name, methodName);
2053 expect(getter.variable, field); 2067 expect(getter.variable, field);
2054 expect(getter.functions, hasLength(0)); 2068 expect(getter.functions, hasLength(0));
2055 expect(getter.labels, hasLength(0)); 2069 expect(getter.labels, hasLength(0));
2056 expect(getter.localVariables, hasLength(0)); 2070 expect(getter.localVariables, hasLength(0));
2057 expect(getter.parameters, hasLength(0)); 2071 expect(getter.parameters, hasLength(0));
2058 } 2072 }
2059 2073
2060 void test_visitMethodDeclaration_minimal() { 2074 void test_visitMethodDeclaration_minimal() {
2061 // T m() {} 2075 // T m() {}
2062 String methodName = "m"; 2076 String methodName = "m";
2063 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( 2077 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2(
2064 null, 2078 null,
2065 AstFactory.typeName4('T'), 2079 AstTestFactory.typeName4('T'),
2066 null, 2080 null,
2067 null, 2081 null,
2068 AstFactory.identifier3(methodName), 2082 AstTestFactory.identifier3(methodName),
2069 AstFactory.formalParameterList(), 2083 AstTestFactory.formalParameterList(),
2070 AstFactory.blockFunctionBody2()); 2084 AstTestFactory.blockFunctionBody2());
2071 methodDeclaration.documentationComment = AstFactory.documentationComment( 2085 methodDeclaration.documentationComment = AstTestFactory
2072 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); 2086 .documentationComment(
2087 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []);
2073 methodDeclaration.endToken.offset = 80; 2088 methodDeclaration.endToken.offset = 80;
2074 2089
2075 ElementHolder holder = buildElementsForAst(methodDeclaration); 2090 ElementHolder holder = buildElementsForAst(methodDeclaration);
2076 List<MethodElement> methods = holder.methods; 2091 List<MethodElement> methods = holder.methods;
2077 expect(methods, hasLength(1)); 2092 expect(methods, hasLength(1));
2078 MethodElement method = methods[0]; 2093 MethodElement method = methods[0];
2079 expect(method, isNotNull); 2094 expect(method, isNotNull);
2080 assertHasCodeRange(method, 50, 31); 2095 assertHasCodeRange(method, 50, 31);
2081 expect(method.documentationComment, '/// aaa'); 2096 expect(method.documentationComment, '/// aaa');
2082 expect(method.hasImplicitReturnType, isFalse); 2097 expect(method.hasImplicitReturnType, isFalse);
2083 expect(method.name, methodName); 2098 expect(method.name, methodName);
2084 expect(method.functions, hasLength(0)); 2099 expect(method.functions, hasLength(0));
2085 expect(method.labels, hasLength(0)); 2100 expect(method.labels, hasLength(0));
2086 expect(method.localVariables, hasLength(0)); 2101 expect(method.localVariables, hasLength(0));
2087 expect(method.parameters, hasLength(0)); 2102 expect(method.parameters, hasLength(0));
2088 expect(method.typeParameters, hasLength(0)); 2103 expect(method.typeParameters, hasLength(0));
2089 expect(method.isAbstract, isFalse); 2104 expect(method.isAbstract, isFalse);
2090 expect(method.isExternal, isFalse); 2105 expect(method.isExternal, isFalse);
2091 expect(method.isStatic, isFalse); 2106 expect(method.isStatic, isFalse);
2092 expect(method.isSynthetic, isFalse); 2107 expect(method.isSynthetic, isFalse);
2093 } 2108 }
2094 2109
2095 void test_visitMethodDeclaration_operator() { 2110 void test_visitMethodDeclaration_operator() {
2096 // operator +(addend) {} 2111 // operator +(addend) {}
2097 String methodName = "+"; 2112 String methodName = "+";
2098 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( 2113 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2(
2099 null, 2114 null,
2100 null, 2115 null,
2101 null, 2116 null,
2102 Keyword.OPERATOR, 2117 Keyword.OPERATOR,
2103 AstFactory.identifier3(methodName), 2118 AstTestFactory.identifier3(methodName),
2104 AstFactory 2119 AstTestFactory.formalParameterList(
2105 .formalParameterList([AstFactory.simpleFormalParameter3("addend")]), 2120 [AstTestFactory.simpleFormalParameter3("addend")]),
2106 AstFactory.blockFunctionBody2()); 2121 AstTestFactory.blockFunctionBody2());
2107 2122
2108 ElementHolder holder = buildElementsForAst(methodDeclaration); 2123 ElementHolder holder = buildElementsForAst(methodDeclaration);
2109 List<MethodElement> methods = holder.methods; 2124 List<MethodElement> methods = holder.methods;
2110 expect(methods, hasLength(1)); 2125 expect(methods, hasLength(1));
2111 MethodElement method = methods[0]; 2126 MethodElement method = methods[0];
2112 expect(method, isNotNull); 2127 expect(method, isNotNull);
2113 expect(method.hasImplicitReturnType, isTrue); 2128 expect(method.hasImplicitReturnType, isTrue);
2114 expect(method.name, methodName); 2129 expect(method.name, methodName);
2115 expect(method.functions, hasLength(0)); 2130 expect(method.functions, hasLength(0));
2116 expect(method.labels, hasLength(0)); 2131 expect(method.labels, hasLength(0));
2117 expect(method.localVariables, hasLength(0)); 2132 expect(method.localVariables, hasLength(0));
2118 expect(method.parameters, hasLength(1)); 2133 expect(method.parameters, hasLength(1));
2119 expect(method.typeParameters, hasLength(0)); 2134 expect(method.typeParameters, hasLength(0));
2120 expect(method.isAbstract, isFalse); 2135 expect(method.isAbstract, isFalse);
2121 expect(method.isExternal, isFalse); 2136 expect(method.isExternal, isFalse);
2122 expect(method.isStatic, isFalse); 2137 expect(method.isStatic, isFalse);
2123 expect(method.isSynthetic, isFalse); 2138 expect(method.isSynthetic, isFalse);
2124 } 2139 }
2125 2140
2126 void test_visitMethodDeclaration_setter() { 2141 void test_visitMethodDeclaration_setter() {
2127 // set m() {} 2142 // set m() {}
2128 String methodName = "m"; 2143 String methodName = "m";
2129 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( 2144 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2(
2130 null, 2145 null,
2131 null, 2146 null,
2132 Keyword.SET, 2147 Keyword.SET,
2133 null, 2148 null,
2134 AstFactory.identifier3(methodName), 2149 AstTestFactory.identifier3(methodName),
2135 AstFactory.formalParameterList(), 2150 AstTestFactory.formalParameterList(),
2136 AstFactory.blockFunctionBody2()); 2151 AstTestFactory.blockFunctionBody2());
2137 methodDeclaration.documentationComment = AstFactory.documentationComment( 2152 methodDeclaration.documentationComment = AstTestFactory
2138 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); 2153 .documentationComment(
2154 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []);
2139 methodDeclaration.endToken.offset = 80; 2155 methodDeclaration.endToken.offset = 80;
2140 2156
2141 ElementHolder holder = buildElementsForAst(methodDeclaration); 2157 ElementHolder holder = buildElementsForAst(methodDeclaration);
2142 List<FieldElement> fields = holder.fields; 2158 List<FieldElement> fields = holder.fields;
2143 expect(fields, hasLength(1)); 2159 expect(fields, hasLength(1));
2144 FieldElement field = fields[0]; 2160 FieldElement field = fields[0];
2145 expect(field, isNotNull); 2161 expect(field, isNotNull);
2146 expect(field.name, methodName); 2162 expect(field.name, methodName);
2147 expect(field.isSynthetic, isTrue); 2163 expect(field.isSynthetic, isTrue);
2148 expect(field.getter, isNull); 2164 expect(field.getter, isNull);
(...skipping 12 matching lines...) Expand all
2161 expect(setter.variable, field); 2177 expect(setter.variable, field);
2162 expect(setter.functions, hasLength(0)); 2178 expect(setter.functions, hasLength(0));
2163 expect(setter.labels, hasLength(0)); 2179 expect(setter.labels, hasLength(0));
2164 expect(setter.localVariables, hasLength(0)); 2180 expect(setter.localVariables, hasLength(0));
2165 expect(setter.parameters, hasLength(0)); 2181 expect(setter.parameters, hasLength(0));
2166 } 2182 }
2167 2183
2168 void test_visitMethodDeclaration_setter_abstract() { 2184 void test_visitMethodDeclaration_setter_abstract() {
2169 // set m(); 2185 // set m();
2170 String methodName = "m"; 2186 String methodName = "m";
2171 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( 2187 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2(
2172 null, 2188 null,
2173 null, 2189 null,
2174 Keyword.SET, 2190 Keyword.SET,
2175 null, 2191 null,
2176 AstFactory.identifier3(methodName), 2192 AstTestFactory.identifier3(methodName),
2177 AstFactory.formalParameterList(), 2193 AstTestFactory.formalParameterList(),
2178 AstFactory.emptyFunctionBody()); 2194 AstTestFactory.emptyFunctionBody());
2179 2195
2180 ElementHolder holder = buildElementsForAst(methodDeclaration); 2196 ElementHolder holder = buildElementsForAst(methodDeclaration);
2181 List<FieldElement> fields = holder.fields; 2197 List<FieldElement> fields = holder.fields;
2182 expect(fields, hasLength(1)); 2198 expect(fields, hasLength(1));
2183 FieldElement field = fields[0]; 2199 FieldElement field = fields[0];
2184 expect(field, isNotNull); 2200 expect(field, isNotNull);
2185 expect(field.name, methodName); 2201 expect(field.name, methodName);
2186 expect(field.isSynthetic, isTrue); 2202 expect(field.isSynthetic, isTrue);
2187 expect(field.getter, isNull); 2203 expect(field.getter, isNull);
2188 PropertyAccessorElement setter = field.setter; 2204 PropertyAccessorElement setter = field.setter;
2189 expect(setter, isNotNull); 2205 expect(setter, isNotNull);
2190 expect(setter.hasImplicitReturnType, isTrue); 2206 expect(setter.hasImplicitReturnType, isTrue);
2191 expect(setter.isAbstract, isTrue); 2207 expect(setter.isAbstract, isTrue);
2192 expect(setter.isExternal, isFalse); 2208 expect(setter.isExternal, isFalse);
2193 expect(setter.isSetter, isTrue); 2209 expect(setter.isSetter, isTrue);
2194 expect(setter.isSynthetic, isFalse); 2210 expect(setter.isSynthetic, isFalse);
2195 expect(setter.name, "$methodName="); 2211 expect(setter.name, "$methodName=");
2196 expect(setter.displayName, methodName); 2212 expect(setter.displayName, methodName);
2197 expect(setter.variable, field); 2213 expect(setter.variable, field);
2198 expect(setter.functions, hasLength(0)); 2214 expect(setter.functions, hasLength(0));
2199 expect(setter.labels, hasLength(0)); 2215 expect(setter.labels, hasLength(0));
2200 expect(setter.localVariables, hasLength(0)); 2216 expect(setter.localVariables, hasLength(0));
2201 expect(setter.parameters, hasLength(0)); 2217 expect(setter.parameters, hasLength(0));
2202 } 2218 }
2203 2219
2204 void test_visitMethodDeclaration_setter_external() { 2220 void test_visitMethodDeclaration_setter_external() {
2205 // external m(); 2221 // external m();
2206 String methodName = "m"; 2222 String methodName = "m";
2207 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration( 2223 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration(
2208 null, 2224 null,
2209 null, 2225 null,
2210 Keyword.SET, 2226 Keyword.SET,
2211 null, 2227 null,
2212 AstFactory.identifier3(methodName), 2228 AstTestFactory.identifier3(methodName),
2213 AstFactory.formalParameterList()); 2229 AstTestFactory.formalParameterList());
2214 methodDeclaration.externalKeyword = 2230 methodDeclaration.externalKeyword =
2215 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); 2231 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL);
2216 2232
2217 ElementHolder holder = buildElementsForAst(methodDeclaration); 2233 ElementHolder holder = buildElementsForAst(methodDeclaration);
2218 List<FieldElement> fields = holder.fields; 2234 List<FieldElement> fields = holder.fields;
2219 expect(fields, hasLength(1)); 2235 expect(fields, hasLength(1));
2220 FieldElement field = fields[0]; 2236 FieldElement field = fields[0];
2221 expect(field, isNotNull); 2237 expect(field, isNotNull);
2222 expect(field.name, methodName); 2238 expect(field.name, methodName);
2223 expect(field.isSynthetic, isTrue); 2239 expect(field.isSynthetic, isTrue);
(...skipping 10 matching lines...) Expand all
2234 expect(setter.variable, field); 2250 expect(setter.variable, field);
2235 expect(setter.functions, hasLength(0)); 2251 expect(setter.functions, hasLength(0));
2236 expect(setter.labels, hasLength(0)); 2252 expect(setter.labels, hasLength(0));
2237 expect(setter.localVariables, hasLength(0)); 2253 expect(setter.localVariables, hasLength(0));
2238 expect(setter.parameters, hasLength(0)); 2254 expect(setter.parameters, hasLength(0));
2239 } 2255 }
2240 2256
2241 void test_visitMethodDeclaration_static() { 2257 void test_visitMethodDeclaration_static() {
2242 // static m() {} 2258 // static m() {}
2243 String methodName = "m"; 2259 String methodName = "m";
2244 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( 2260 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2(
2245 Keyword.STATIC, 2261 Keyword.STATIC,
2246 null, 2262 null,
2247 null, 2263 null,
2248 null, 2264 null,
2249 AstFactory.identifier3(methodName), 2265 AstTestFactory.identifier3(methodName),
2250 AstFactory.formalParameterList(), 2266 AstTestFactory.formalParameterList(),
2251 AstFactory.blockFunctionBody2()); 2267 AstTestFactory.blockFunctionBody2());
2252 ElementHolder holder = buildElementsForAst(methodDeclaration); 2268 ElementHolder holder = buildElementsForAst(methodDeclaration);
2253 List<MethodElement> methods = holder.methods; 2269 List<MethodElement> methods = holder.methods;
2254 expect(methods, hasLength(1)); 2270 expect(methods, hasLength(1));
2255 MethodElement method = methods[0]; 2271 MethodElement method = methods[0];
2256 expect(method, isNotNull); 2272 expect(method, isNotNull);
2257 expect(method.hasImplicitReturnType, isTrue); 2273 expect(method.hasImplicitReturnType, isTrue);
2258 expect(method.name, methodName); 2274 expect(method.name, methodName);
2259 expect(method.functions, hasLength(0)); 2275 expect(method.functions, hasLength(0));
2260 expect(method.labels, hasLength(0)); 2276 expect(method.labels, hasLength(0));
2261 expect(method.localVariables, hasLength(0)); 2277 expect(method.localVariables, hasLength(0));
2262 expect(method.parameters, hasLength(0)); 2278 expect(method.parameters, hasLength(0));
2263 expect(method.typeParameters, hasLength(0)); 2279 expect(method.typeParameters, hasLength(0));
2264 expect(method.isAbstract, isFalse); 2280 expect(method.isAbstract, isFalse);
2265 expect(method.isExternal, isFalse); 2281 expect(method.isExternal, isFalse);
2266 expect(method.isStatic, isTrue); 2282 expect(method.isStatic, isTrue);
2267 expect(method.isSynthetic, isFalse); 2283 expect(method.isSynthetic, isFalse);
2268 } 2284 }
2269 2285
2270 void test_visitMethodDeclaration_typeParameters() { 2286 void test_visitMethodDeclaration_typeParameters() {
2271 // m<E>() {} 2287 // m<E>() {}
2272 String methodName = "m"; 2288 String methodName = "m";
2273 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( 2289 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2(
2274 null, 2290 null,
2275 null, 2291 null,
2276 null, 2292 null,
2277 null, 2293 null,
2278 AstFactory.identifier3(methodName), 2294 AstTestFactory.identifier3(methodName),
2279 AstFactory.formalParameterList(), 2295 AstTestFactory.formalParameterList(),
2280 AstFactory.blockFunctionBody2()); 2296 AstTestFactory.blockFunctionBody2());
2281 methodDeclaration.typeParameters = AstFactory.typeParameterList(['E']); 2297 methodDeclaration.typeParameters = AstTestFactory.typeParameterList(['E']);
2282 2298
2283 ElementHolder holder = buildElementsForAst(methodDeclaration); 2299 ElementHolder holder = buildElementsForAst(methodDeclaration);
2284 List<MethodElement> methods = holder.methods; 2300 List<MethodElement> methods = holder.methods;
2285 expect(methods, hasLength(1)); 2301 expect(methods, hasLength(1));
2286 MethodElement method = methods[0]; 2302 MethodElement method = methods[0];
2287 expect(method, isNotNull); 2303 expect(method, isNotNull);
2288 expect(method.hasImplicitReturnType, isTrue); 2304 expect(method.hasImplicitReturnType, isTrue);
2289 expect(method.name, methodName); 2305 expect(method.name, methodName);
2290 expect(method.functions, hasLength(0)); 2306 expect(method.functions, hasLength(0));
2291 expect(method.labels, hasLength(0)); 2307 expect(method.labels, hasLength(0));
2292 expect(method.localVariables, hasLength(0)); 2308 expect(method.localVariables, hasLength(0));
2293 expect(method.parameters, hasLength(0)); 2309 expect(method.parameters, hasLength(0));
2294 expect(method.typeParameters, hasLength(1)); 2310 expect(method.typeParameters, hasLength(1));
2295 expect(method.isAbstract, isFalse); 2311 expect(method.isAbstract, isFalse);
2296 expect(method.isExternal, isFalse); 2312 expect(method.isExternal, isFalse);
2297 expect(method.isStatic, isFalse); 2313 expect(method.isStatic, isFalse);
2298 expect(method.isSynthetic, isFalse); 2314 expect(method.isSynthetic, isFalse);
2299 } 2315 }
2300 2316
2301 void test_visitTypeAlias_minimal() { 2317 void test_visitTypeAlias_minimal() {
2302 String aliasName = "F"; 2318 String aliasName = "F";
2303 TypeAlias typeAlias = AstFactory.typeAlias(null, aliasName, null, null); 2319 TypeAlias typeAlias = AstTestFactory.typeAlias(null, aliasName, null, null);
2304 ElementHolder holder = buildElementsForAst(typeAlias); 2320 ElementHolder holder = buildElementsForAst(typeAlias);
2305 List<FunctionTypeAliasElement> aliases = holder.typeAliases; 2321 List<FunctionTypeAliasElement> aliases = holder.typeAliases;
2306 expect(aliases, hasLength(1)); 2322 expect(aliases, hasLength(1));
2307 FunctionTypeAliasElement alias = aliases[0]; 2323 FunctionTypeAliasElement alias = aliases[0];
2308 expect(alias, isNotNull); 2324 expect(alias, isNotNull);
2309 expect(alias.name, aliasName); 2325 expect(alias.name, aliasName);
2310 expect(alias.type, isNotNull); 2326 expect(alias.type, isNotNull);
2311 expect(alias.isSynthetic, isFalse); 2327 expect(alias.isSynthetic, isFalse);
2312 } 2328 }
2313 2329
2314 void test_visitTypeAlias_withFormalParameters() { 2330 void test_visitTypeAlias_withFormalParameters() {
2315 String aliasName = "F"; 2331 String aliasName = "F";
2316 String firstParameterName = "x"; 2332 String firstParameterName = "x";
2317 String secondParameterName = "y"; 2333 String secondParameterName = "y";
2318 TypeAlias typeAlias = AstFactory.typeAlias( 2334 TypeAlias typeAlias = AstTestFactory.typeAlias(
2319 null, 2335 null,
2320 aliasName, 2336 aliasName,
2321 AstFactory.typeParameterList(), 2337 AstTestFactory.typeParameterList(),
2322 AstFactory.formalParameterList([ 2338 AstTestFactory.formalParameterList([
2323 AstFactory.simpleFormalParameter3(firstParameterName), 2339 AstTestFactory.simpleFormalParameter3(firstParameterName),
2324 AstFactory.simpleFormalParameter3(secondParameterName) 2340 AstTestFactory.simpleFormalParameter3(secondParameterName)
2325 ])); 2341 ]));
2326 typeAlias.beginToken.offset = 50; 2342 typeAlias.beginToken.offset = 50;
2327 typeAlias.endToken.offset = 80; 2343 typeAlias.endToken.offset = 80;
2328 ElementHolder holder = buildElementsForAst(typeAlias); 2344 ElementHolder holder = buildElementsForAst(typeAlias);
2329 List<FunctionTypeAliasElement> aliases = holder.typeAliases; 2345 List<FunctionTypeAliasElement> aliases = holder.typeAliases;
2330 expect(aliases, hasLength(1)); 2346 expect(aliases, hasLength(1));
2331 FunctionTypeAliasElement alias = aliases[0]; 2347 FunctionTypeAliasElement alias = aliases[0];
2332 expect(alias, isNotNull); 2348 expect(alias, isNotNull);
2333 assertHasCodeRange(alias, 50, 31); 2349 assertHasCodeRange(alias, 50, 31);
2334 expect(alias.name, aliasName); 2350 expect(alias.name, aliasName);
2335 expect(alias.type, isNotNull); 2351 expect(alias.type, isNotNull);
2336 expect(alias.isSynthetic, isFalse); 2352 expect(alias.isSynthetic, isFalse);
2337 List<VariableElement> parameters = alias.parameters; 2353 List<VariableElement> parameters = alias.parameters;
2338 expect(parameters, hasLength(2)); 2354 expect(parameters, hasLength(2));
2339 expect(parameters[0].name, firstParameterName); 2355 expect(parameters[0].name, firstParameterName);
2340 expect(parameters[1].name, secondParameterName); 2356 expect(parameters[1].name, secondParameterName);
2341 List<TypeParameterElement> typeParameters = alias.typeParameters; 2357 List<TypeParameterElement> typeParameters = alias.typeParameters;
2342 expect(typeParameters, isNotNull); 2358 expect(typeParameters, isNotNull);
2343 expect(typeParameters, hasLength(0)); 2359 expect(typeParameters, hasLength(0));
2344 } 2360 }
2345 2361
2346 void test_visitTypeAlias_withTypeParameters() { 2362 void test_visitTypeAlias_withTypeParameters() {
2347 String aliasName = "F"; 2363 String aliasName = "F";
2348 String firstTypeParameterName = "A"; 2364 String firstTypeParameterName = "A";
2349 String secondTypeParameterName = "B"; 2365 String secondTypeParameterName = "B";
2350 TypeAlias typeAlias = AstFactory.typeAlias( 2366 TypeAlias typeAlias = AstTestFactory.typeAlias(
2351 null, 2367 null,
2352 aliasName, 2368 aliasName,
2353 AstFactory.typeParameterList( 2369 AstTestFactory.typeParameterList(
2354 [firstTypeParameterName, secondTypeParameterName]), 2370 [firstTypeParameterName, secondTypeParameterName]),
2355 AstFactory.formalParameterList()); 2371 AstTestFactory.formalParameterList());
2356 ElementHolder holder = buildElementsForAst(typeAlias); 2372 ElementHolder holder = buildElementsForAst(typeAlias);
2357 List<FunctionTypeAliasElement> aliases = holder.typeAliases; 2373 List<FunctionTypeAliasElement> aliases = holder.typeAliases;
2358 expect(aliases, hasLength(1)); 2374 expect(aliases, hasLength(1));
2359 FunctionTypeAliasElement alias = aliases[0]; 2375 FunctionTypeAliasElement alias = aliases[0];
2360 expect(alias, isNotNull); 2376 expect(alias, isNotNull);
2361 expect(alias.name, aliasName); 2377 expect(alias.name, aliasName);
2362 expect(alias.type, isNotNull); 2378 expect(alias.type, isNotNull);
2363 expect(alias.isSynthetic, isFalse); 2379 expect(alias.isSynthetic, isFalse);
2364 List<VariableElement> parameters = alias.parameters; 2380 List<VariableElement> parameters = alias.parameters;
2365 expect(parameters, isNotNull); 2381 expect(parameters, isNotNull);
2366 expect(parameters, hasLength(0)); 2382 expect(parameters, hasLength(0));
2367 List<TypeParameterElement> typeParameters = alias.typeParameters; 2383 List<TypeParameterElement> typeParameters = alias.typeParameters;
2368 expect(typeParameters, hasLength(2)); 2384 expect(typeParameters, hasLength(2));
2369 expect(typeParameters[0].name, firstTypeParameterName); 2385 expect(typeParameters[0].name, firstTypeParameterName);
2370 expect(typeParameters[1].name, secondTypeParameterName); 2386 expect(typeParameters[1].name, secondTypeParameterName);
2371 } 2387 }
2372 2388
2373 void test_visitTypeParameter() { 2389 void test_visitTypeParameter() {
2374 String parameterName = "E"; 2390 String parameterName = "E";
2375 TypeParameter typeParameter = AstFactory.typeParameter(parameterName); 2391 TypeParameter typeParameter = AstTestFactory.typeParameter(parameterName);
2376 typeParameter.beginToken.offset = 50; 2392 typeParameter.beginToken.offset = 50;
2377 ElementHolder holder = buildElementsForAst(typeParameter); 2393 ElementHolder holder = buildElementsForAst(typeParameter);
2378 List<TypeParameterElement> typeParameters = holder.typeParameters; 2394 List<TypeParameterElement> typeParameters = holder.typeParameters;
2379 expect(typeParameters, hasLength(1)); 2395 expect(typeParameters, hasLength(1));
2380 TypeParameterElement typeParameterElement = typeParameters[0]; 2396 TypeParameterElement typeParameterElement = typeParameters[0];
2381 expect(typeParameterElement, isNotNull); 2397 expect(typeParameterElement, isNotNull);
2382 assertHasCodeRange(typeParameterElement, 50, 1); 2398 assertHasCodeRange(typeParameterElement, 50, 1);
2383 expect(typeParameterElement.name, parameterName); 2399 expect(typeParameterElement.name, parameterName);
2384 expect(typeParameterElement.bound, isNull); 2400 expect(typeParameterElement.bound, isNull);
2385 expect(typeParameterElement.isSynthetic, isFalse); 2401 expect(typeParameterElement.isSynthetic, isFalse);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
2468 AnalysisEngine.instance.logger = logger; 2484 AnalysisEngine.instance.logger = logger;
2469 try { 2485 try {
2470 _compilationUnit = ParserTestCase.parseCompilationUnit(code); 2486 _compilationUnit = ParserTestCase.parseCompilationUnit(code);
2471 compilationUnit.accept(visitor); 2487 compilationUnit.accept(visitor);
2472 } finally { 2488 } finally {
2473 expect(logger.log, hasLength(0)); 2489 expect(logger.log, hasLength(0));
2474 AnalysisEngine.instance.logger = Logger.NULL; 2490 AnalysisEngine.instance.logger = Logger.NULL;
2475 } 2491 }
2476 } 2492 }
2477 } 2493 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/dart/ast/ast_test.dart ('k') | pkg/analyzer/test/generated/all_the_rest_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698