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

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

Issue 1668483003: Create ElementAnnotation objects prior to resolution. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.test.generated.all_the_rest_test; 5 library analyzer.test.generated.all_the_rest_test;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/element/element.dart'; 8 import 'package:analyzer/dart/element/element.dart';
9 import 'package:analyzer/dart/element/type.dart'; 9 import 'package:analyzer/dart/element/type.dart';
10 import 'package:analyzer/file_system/physical_file_system.dart'; 10 import 'package:analyzer/file_system/physical_file_system.dart';
11 import 'package:analyzer/src/dart/ast/ast.dart';
11 import 'package:analyzer/src/dart/ast/utilities.dart' hide ConstantEvaluator; 12 import 'package:analyzer/src/dart/ast/utilities.dart' hide ConstantEvaluator;
12 import 'package:analyzer/src/dart/element/builder.dart'; 13 import 'package:analyzer/src/dart/element/builder.dart';
13 import 'package:analyzer/src/dart/element/element.dart'; 14 import 'package:analyzer/src/dart/element/element.dart';
14 import 'package:analyzer/src/generated/engine.dart'; 15 import 'package:analyzer/src/generated/engine.dart';
15 import 'package:analyzer/src/generated/error.dart'; 16 import 'package:analyzer/src/generated/error.dart';
16 import 'package:analyzer/src/generated/java_core.dart'; 17 import 'package:analyzer/src/generated/java_core.dart';
17 import 'package:analyzer/src/generated/java_engine_io.dart'; 18 import 'package:analyzer/src/generated/java_engine_io.dart';
18 import 'package:analyzer/src/generated/java_io.dart'; 19 import 'package:analyzer/src/generated/java_io.dart';
19 import 'package:analyzer/src/generated/resolver.dart'; 20 import 'package:analyzer/src/generated/resolver.dart';
20 import 'package:analyzer/src/generated/scanner.dart'; 21 import 'package:analyzer/src/generated/scanner.dart';
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 DirectoryBasedSourceContainer container = 260 DirectoryBasedSourceContainer container =
260 new DirectoryBasedSourceContainer.con1(dir); 261 new DirectoryBasedSourceContainer.con1(dir);
261 expect(container.contains(source1), isTrue); 262 expect(container.contains(source1), isTrue);
262 expect(container.contains(source2), isTrue); 263 expect(container.contains(source2), isTrue);
263 expect(container.contains(source3), isFalse); 264 expect(container.contains(source3), isFalse);
264 } 265 }
265 } 266 }
266 267
267 @reflectiveTest 268 @reflectiveTest
268 class ElementBuilderTest extends ParserTestCase { 269 class ElementBuilderTest extends ParserTestCase {
270 CompilationUnitElement compilationUnitElement;
271 CompilationUnit compilationUnit;
272
273 /**
274 * Parse the given [code], pass it through [ElementBuilder], and return the
275 * resulting [ElementHolder].
276 */
277 ElementHolder buildElementsForText(String code) {
278 compilationUnit = ParserTestCase.parseCompilationUnit(code);
279 ElementHolder holder = new ElementHolder();
280 ElementBuilder builder = new ElementBuilder(holder, compilationUnitElement);
281 compilationUnit.accept(builder);
282 return holder;
283 }
284
285 /**
286 * Verify that the given [metadata] has exactly one annotation, and that its
287 * [ElementAnnotationImpl] is unresolved.
288 */
289 void checkAnnotation(NodeList<Annotation> metadata) {
290 expect(metadata, hasLength(1));
291 expect(metadata[0], new isInstanceOf<AnnotationImpl>());
292 AnnotationImpl annotation = metadata[0];
293 expect(annotation.elementAnnotation,
294 new isInstanceOf<ElementAnnotationImpl>());
295 ElementAnnotationImpl elementAnnotation = annotation.elementAnnotation;
296 expect(elementAnnotation.element, isNull); // Not yet resolved
297 expect(elementAnnotation.compilationUnit, isNotNull);
298 expect(elementAnnotation.compilationUnit, compilationUnitElement);
299 }
300
301 /**
302 * Verify that the given [element] has exactly one annotation, and that its
303 * [ElementAnnotationImpl] is unresolved.
304 */
305 void checkMetadata(Element element) {
306 expect(element.metadata, hasLength(1));
307 expect(element.metadata[0], new isInstanceOf<ElementAnnotationImpl>());
308 ElementAnnotationImpl elementAnnotation = element.metadata[0];
309 expect(elementAnnotation.element, isNull); // Not yet resolved
310 expect(elementAnnotation.compilationUnit, isNotNull);
311 expect(elementAnnotation.compilationUnit, compilationUnitElement);
312 }
313
269 void fail_visitMethodDeclaration_setter_duplicate() { 314 void fail_visitMethodDeclaration_setter_duplicate() {
270 // https://github.com/dart-lang/sdk/issues/25601 315 // https://github.com/dart-lang/sdk/issues/25601
271 String code = r''' 316 String code = r'''
272 class C { 317 class C {
273 set zzz(x) {} 318 set zzz(x) {}
274 set zzz(y) {} 319 set zzz(y) {}
275 } 320 }
276 '''; 321 ''';
277 CompilationUnit unit = ParserTestCase.parseCompilationUnit(code); 322 ClassElement classElement = buildElementsForText(code).types[0];
278 ElementHolder holder = new ElementHolder();
279 ElementBuilder builder = new ElementBuilder(holder);
280 unit.accept(builder);
281 ClassElement classElement = holder.types[0];
282 for (PropertyAccessorElement accessor in classElement.accessors) { 323 for (PropertyAccessorElement accessor in classElement.accessors) {
283 expect(accessor.variable.setter, same(accessor)); 324 expect(accessor.variable.setter, same(accessor));
284 } 325 }
285 } 326 }
286 327
328 @override
329 void setUp() {
330 super.setUp();
331 compilationUnitElement = new CompilationUnitElementImpl('test.dart');
332 }
333
334 void test_metadata_fieldDeclaration() {
335 List<FieldElement> fields =
336 buildElementsForText('class C { @a int x, y; }').types[0].fields;
337 checkMetadata(fields[0]);
338 checkMetadata(fields[1]);
339 expect(fields[0].metadata, same(fields[1].metadata));
340 }
341
342 void test_metadata_localVariableDeclaration() {
343 List<LocalVariableElement> localVariables =
344 buildElementsForText('f() { @a int x, y; }')
345 .functions[0]
346 .localVariables;
347 checkMetadata(localVariables[0]);
348 checkMetadata(localVariables[1]);
349 expect(localVariables[0].metadata, same(localVariables[1].metadata));
350 }
351
352 void test_metadata_topLevelVariableDeclaration() {
353 List<TopLevelVariableElement> topLevelVariables =
354 buildElementsForText('@a int x, y;').topLevelVariables;
355 checkMetadata(topLevelVariables[0]);
356 checkMetadata(topLevelVariables[1]);
357 expect(topLevelVariables[0].metadata, same(topLevelVariables[1].metadata));
358 }
359
360 void test_metadata_visitClassDeclaration() {
361 ClassElement classElement = buildElementsForText('@a class C {}').types[0];
362 checkMetadata(classElement);
363 }
364
365 void test_metadata_visitClassTypeAlias() {
366 ClassElement classElement =
367 buildElementsForText('@a class C = D with E;').types[0];
368 checkMetadata(classElement);
369 }
370
371 void test_metadata_visitConstructorDeclaration() {
372 ConstructorElement constructorElement =
373 buildElementsForText('class C { @a C(); }').types[0].constructors[0];
374 checkMetadata(constructorElement);
375 }
376
377 void test_metadata_visitDeclaredIdentifier() {
378 LocalVariableElement localVariableElement =
379 buildElementsForText('f() { for (@a var x in y) {} }')
380 .functions[0]
381 .localVariables[0];
382 checkMetadata(localVariableElement);
383 }
384
385 void test_metadata_visitEnumDeclaration() {
386 ClassElement classElement =
387 buildElementsForText('@a enum E { v }').enums[0];
388 checkMetadata(classElement);
389 }
390
391 void test_metadata_visitExportDirective() {
392 buildElementsForText('@a export "foo.dart";');
393 expect(compilationUnit.directives[0], new isInstanceOf<ExportDirective>());
394 ExportDirective exportDirective = compilationUnit.directives[0];
395 checkAnnotation(exportDirective.metadata);
396 }
397
398 void test_metadata_visitFieldFormalParameter() {
399 ParameterElement parameterElement =
400 buildElementsForText('class C { var x; C(@a this.x); }')
401 .types[0]
402 .constructors[0]
403 .parameters[0];
404 checkMetadata(parameterElement);
405 }
406
407 void test_metadata_visitFunctionDeclaration_function() {
408 FunctionElement functionElement =
409 buildElementsForText('@a f() {}').functions[0];
410 checkMetadata(functionElement);
411 }
412
413 void test_metadata_visitFunctionDeclaration_getter() {
414 PropertyAccessorElement propertyAccessorElement =
415 buildElementsForText('@a get f => null;').accessors[0];
416 checkMetadata(propertyAccessorElement);
417 }
418
419 void test_metadata_visitFunctionDeclaration_setter() {
420 PropertyAccessorElement propertyAccessorElement =
421 buildElementsForText('@a set f(value) {}').accessors[0];
422 checkMetadata(propertyAccessorElement);
423 }
424
425 void test_metadata_visitFunctionTypeAlias() {
426 FunctionTypeAliasElement functionTypeAliasElement =
427 buildElementsForText('@a typedef F();').typeAliases[0];
428 checkMetadata(functionTypeAliasElement);
429 }
430
431 void test_metadata_visitFunctionTypedFormalParameter() {
432 ParameterElement parameterElement =
433 buildElementsForText('f(@a g()) {}').functions[0].parameters[0];
434 checkMetadata(parameterElement);
435 }
436
437 void test_metadata_visitImportDirective() {
438 buildElementsForText('@a import "foo.dart";');
439 expect(compilationUnit.directives[0], new isInstanceOf<ImportDirective>());
440 ImportDirective importDirective = compilationUnit.directives[0];
441 checkAnnotation(importDirective.metadata);
442 }
443
444 void test_metadata_visitLibraryDirective() {
445 buildElementsForText('@a library L;');
446 expect(compilationUnit.directives[0], new isInstanceOf<LibraryDirective>());
447 LibraryDirective libraryDirective = compilationUnit.directives[0];
448 checkAnnotation(libraryDirective.metadata);
449 }
450
451 void test_metadata_visitMethodDeclaration_getter() {
452 PropertyAccessorElement propertyAccessorElement =
453 buildElementsForText('class C { @a get m => null; }')
454 .types[0]
455 .accessors[0];
456 checkMetadata(propertyAccessorElement);
457 }
458
459 void test_metadata_visitMethodDeclaration_method() {
460 MethodElement methodElement =
461 buildElementsForText('class C { @a m() {} }').types[0].methods[0];
462 checkMetadata(methodElement);
463 }
464
465 void test_metadata_visitMethodDeclaration_setter() {
466 PropertyAccessorElement propertyAccessorElement =
467 buildElementsForText('class C { @a set f(value) {} }')
468 .types[0]
469 .accessors[0];
470 checkMetadata(propertyAccessorElement);
471 }
472
473 void test_metadata_visitPartDirective() {
474 buildElementsForText('@a part "foo.dart";');
475 expect(compilationUnit.directives[0], new isInstanceOf<PartDirective>());
476 PartDirective partDirective = compilationUnit.directives[0];
477 checkAnnotation(partDirective.metadata);
478 }
479
480 void test_metadata_visitPartOfDirective() {
481 // We don't build ElementAnnotation objects for `part of` directives, since
482 // analyzer ignores them in favor of annotations on the library directive.
483 buildElementsForText('@a part of L;');
484 expect(compilationUnit.directives[0], new isInstanceOf<PartOfDirective>());
485 PartOfDirective partOfDirective = compilationUnit.directives[0];
486 expect(partOfDirective.metadata, hasLength(1));
487 expect(partOfDirective.metadata[0].elementAnnotation, isNull);
488 }
489
490 void test_metadata_visitSimpleFormalParameter() {
491 ParameterElement parameterElement =
492 buildElementsForText('f(@a x) {}').functions[0].parameters[0];
493 checkMetadata(parameterElement);
494 }
495
496 void test_metadata_visitTypeParameter() {
497 TypeParameterElement typeParameterElement =
498 buildElementsForText('class C<@a T> {}').types[0].typeParameters[0];
499 checkMetadata(typeParameterElement);
500 }
501
287 void test_visitCatchClause() { 502 void test_visitCatchClause() {
288 // } catch (e, s) { 503 // } catch (e, s) {
289 ElementHolder holder = new ElementHolder(); 504 ElementHolder holder = new ElementHolder();
290 ElementBuilder builder = new ElementBuilder(holder); 505 ElementBuilder builder = _makeBuilder(holder);
291 String exceptionParameterName = "e"; 506 String exceptionParameterName = "e";
292 String stackParameterName = "s"; 507 String stackParameterName = "s";
293 CatchClause clause = 508 CatchClause clause =
294 AstFactory.catchClause2(exceptionParameterName, stackParameterName); 509 AstFactory.catchClause2(exceptionParameterName, stackParameterName);
295 clause.accept(builder); 510 clause.accept(builder);
296 511
297 List<LocalVariableElement> variables = holder.localVariables; 512 List<LocalVariableElement> variables = holder.localVariables;
298 expect(variables, hasLength(2)); 513 expect(variables, hasLength(2));
299 VariableElement exceptionVariable = variables[0]; 514 VariableElement exceptionVariable = variables[0];
300 expect(exceptionVariable, isNotNull); 515 expect(exceptionVariable, isNotNull);
301 expect(exceptionVariable.name, exceptionParameterName); 516 expect(exceptionVariable.name, exceptionParameterName);
302 expect(exceptionVariable.hasImplicitType, isTrue); 517 expect(exceptionVariable.hasImplicitType, isTrue);
303 expect(exceptionVariable.isSynthetic, isFalse); 518 expect(exceptionVariable.isSynthetic, isFalse);
304 expect(exceptionVariable.isConst, isFalse); 519 expect(exceptionVariable.isConst, isFalse);
305 expect(exceptionVariable.isFinal, isFalse); 520 expect(exceptionVariable.isFinal, isFalse);
306 expect(exceptionVariable.initializer, isNull); 521 expect(exceptionVariable.initializer, isNull);
307 VariableElement stackVariable = variables[1]; 522 VariableElement stackVariable = variables[1];
308 expect(stackVariable, isNotNull); 523 expect(stackVariable, isNotNull);
309 expect(stackVariable.name, stackParameterName); 524 expect(stackVariable.name, stackParameterName);
310 expect(stackVariable.isSynthetic, isFalse); 525 expect(stackVariable.isSynthetic, isFalse);
311 expect(stackVariable.isConst, isFalse); 526 expect(stackVariable.isConst, isFalse);
312 expect(stackVariable.isFinal, isFalse); 527 expect(stackVariable.isFinal, isFalse);
313 expect(stackVariable.initializer, isNull); 528 expect(stackVariable.initializer, isNull);
314 } 529 }
315 530
316 void test_visitCatchClause_withType() { 531 void test_visitCatchClause_withType() {
317 // } on E catch (e) { 532 // } on E catch (e) {
318 ElementHolder holder = new ElementHolder(); 533 ElementHolder holder = new ElementHolder();
319 ElementBuilder builder = new ElementBuilder(holder); 534 ElementBuilder builder = _makeBuilder(holder);
320 String exceptionParameterName = "e"; 535 String exceptionParameterName = "e";
321 CatchClause clause = AstFactory.catchClause4( 536 CatchClause clause = AstFactory.catchClause4(
322 AstFactory.typeName4('E'), exceptionParameterName); 537 AstFactory.typeName4('E'), exceptionParameterName);
323 clause.accept(builder); 538 clause.accept(builder);
324 539
325 List<LocalVariableElement> variables = holder.localVariables; 540 List<LocalVariableElement> variables = holder.localVariables;
326 expect(variables, hasLength(1)); 541 expect(variables, hasLength(1));
327 VariableElement exceptionVariable = variables[0]; 542 VariableElement exceptionVariable = variables[0];
328 expect(exceptionVariable, isNotNull); 543 expect(exceptionVariable, isNotNull);
329 expect(exceptionVariable.name, exceptionParameterName); 544 expect(exceptionVariable.name, exceptionParameterName);
330 expect(exceptionVariable.hasImplicitType, isFalse); 545 expect(exceptionVariable.hasImplicitType, isFalse);
331 } 546 }
332 547
333 void test_visitClassDeclaration_abstract() { 548 void test_visitClassDeclaration_abstract() {
334 ElementHolder holder = new ElementHolder(); 549 ElementHolder holder = new ElementHolder();
335 ElementBuilder builder = new ElementBuilder(holder); 550 ElementBuilder builder = _makeBuilder(holder);
336 String className = "C"; 551 String className = "C";
337 ClassDeclaration classDeclaration = AstFactory.classDeclaration( 552 ClassDeclaration classDeclaration = AstFactory.classDeclaration(
338 Keyword.ABSTRACT, className, null, null, null, null); 553 Keyword.ABSTRACT, className, null, null, null, null);
339 classDeclaration.accept(builder); 554 classDeclaration.accept(builder);
340 List<ClassElement> types = holder.types; 555 List<ClassElement> types = holder.types;
341 expect(types, hasLength(1)); 556 expect(types, hasLength(1));
342 ClassElement type = types[0]; 557 ClassElement type = types[0];
343 expect(type, isNotNull); 558 expect(type, isNotNull);
344 expect(type.name, className); 559 expect(type.name, className);
345 List<TypeParameterElement> typeParameters = type.typeParameters; 560 List<TypeParameterElement> typeParameters = type.typeParameters;
346 expect(typeParameters, hasLength(0)); 561 expect(typeParameters, hasLength(0));
347 expect(type.isAbstract, isTrue); 562 expect(type.isAbstract, isTrue);
348 expect(type.isMixinApplication, isFalse); 563 expect(type.isMixinApplication, isFalse);
349 expect(type.isSynthetic, isFalse); 564 expect(type.isSynthetic, isFalse);
350 } 565 }
351 566
352 void test_visitClassDeclaration_minimal() { 567 void test_visitClassDeclaration_minimal() {
353 ElementHolder holder = new ElementHolder(); 568 ElementHolder holder = new ElementHolder();
354 ElementBuilder builder = new ElementBuilder(holder); 569 ElementBuilder builder = _makeBuilder(holder);
355 String className = "C"; 570 String className = "C";
356 ClassDeclaration classDeclaration = 571 ClassDeclaration classDeclaration =
357 AstFactory.classDeclaration(null, className, null, null, null, null); 572 AstFactory.classDeclaration(null, className, null, null, null, null);
358 classDeclaration.documentationComment = AstFactory.documentationComment( 573 classDeclaration.documentationComment = AstFactory.documentationComment(
359 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); 574 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []);
360 classDeclaration.accept(builder); 575 classDeclaration.accept(builder);
361 List<ClassElement> types = holder.types; 576 List<ClassElement> types = holder.types;
362 expect(types, hasLength(1)); 577 expect(types, hasLength(1));
363 ClassElement type = types[0]; 578 ClassElement type = types[0];
364 expect(type, isNotNull); 579 expect(type, isNotNull);
365 expect(type.name, className); 580 expect(type.name, className);
366 List<TypeParameterElement> typeParameters = type.typeParameters; 581 List<TypeParameterElement> typeParameters = type.typeParameters;
367 expect(typeParameters, hasLength(0)); 582 expect(typeParameters, hasLength(0));
368 expect(type.isAbstract, isFalse); 583 expect(type.isAbstract, isFalse);
369 expect(type.isMixinApplication, isFalse); 584 expect(type.isMixinApplication, isFalse);
370 expect(type.isSynthetic, isFalse); 585 expect(type.isSynthetic, isFalse);
371 _assertHasDocRange(type, 50, 7); 586 _assertHasDocRange(type, 50, 7);
372 } 587 }
373 588
374 void test_visitClassDeclaration_parameterized() { 589 void test_visitClassDeclaration_parameterized() {
375 ElementHolder holder = new ElementHolder(); 590 ElementHolder holder = new ElementHolder();
376 ElementBuilder builder = new ElementBuilder(holder); 591 ElementBuilder builder = _makeBuilder(holder);
377 String className = "C"; 592 String className = "C";
378 String firstVariableName = "E"; 593 String firstVariableName = "E";
379 String secondVariableName = "F"; 594 String secondVariableName = "F";
380 ClassDeclaration classDeclaration = AstFactory.classDeclaration( 595 ClassDeclaration classDeclaration = AstFactory.classDeclaration(
381 null, 596 null,
382 className, 597 className,
383 AstFactory.typeParameterList([firstVariableName, secondVariableName]), 598 AstFactory.typeParameterList([firstVariableName, secondVariableName]),
384 null, 599 null,
385 null, 600 null,
386 null); 601 null);
387 classDeclaration.accept(builder); 602 classDeclaration.accept(builder);
388 List<ClassElement> types = holder.types; 603 List<ClassElement> types = holder.types;
389 expect(types, hasLength(1)); 604 expect(types, hasLength(1));
390 ClassElement type = types[0]; 605 ClassElement type = types[0];
391 expect(type, isNotNull); 606 expect(type, isNotNull);
392 expect(type.name, className); 607 expect(type.name, className);
393 List<TypeParameterElement> typeParameters = type.typeParameters; 608 List<TypeParameterElement> typeParameters = type.typeParameters;
394 expect(typeParameters, hasLength(2)); 609 expect(typeParameters, hasLength(2));
395 expect(typeParameters[0].name, firstVariableName); 610 expect(typeParameters[0].name, firstVariableName);
396 expect(typeParameters[1].name, secondVariableName); 611 expect(typeParameters[1].name, secondVariableName);
397 expect(type.isAbstract, isFalse); 612 expect(type.isAbstract, isFalse);
398 expect(type.isMixinApplication, isFalse); 613 expect(type.isMixinApplication, isFalse);
399 expect(type.isSynthetic, isFalse); 614 expect(type.isSynthetic, isFalse);
400 } 615 }
401 616
402 void test_visitClassDeclaration_withMembers() { 617 void test_visitClassDeclaration_withMembers() {
403 ElementHolder holder = new ElementHolder(); 618 ElementHolder holder = new ElementHolder();
404 ElementBuilder builder = new ElementBuilder(holder); 619 ElementBuilder builder = _makeBuilder(holder);
405 String className = "C"; 620 String className = "C";
406 String typeParameterName = "E"; 621 String typeParameterName = "E";
407 String fieldName = "f"; 622 String fieldName = "f";
408 String methodName = "m"; 623 String methodName = "m";
409 ClassDeclaration classDeclaration = AstFactory.classDeclaration( 624 ClassDeclaration classDeclaration = AstFactory.classDeclaration(
410 null, 625 null,
411 className, 626 className,
412 AstFactory.typeParameterList([typeParameterName]), 627 AstFactory.typeParameterList([typeParameterName]),
413 null, 628 null,
414 null, 629 null,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 MethodElement method = methods[0]; 663 MethodElement method = methods[0];
449 expect(method, isNotNull); 664 expect(method, isNotNull);
450 expect(method.name, methodName); 665 expect(method.name, methodName);
451 } 666 }
452 667
453 void test_visitClassTypeAlias() { 668 void test_visitClassTypeAlias() {
454 // class B {} 669 // class B {}
455 // class M {} 670 // class M {}
456 // class C = B with M 671 // class C = B with M
457 ElementHolder holder = new ElementHolder(); 672 ElementHolder holder = new ElementHolder();
458 ElementBuilder builder = new ElementBuilder(holder); 673 ElementBuilder builder = _makeBuilder(holder);
459 ClassElementImpl classB = ElementFactory.classElement2('B', []); 674 ClassElementImpl classB = ElementFactory.classElement2('B', []);
460 ConstructorElementImpl constructorB = 675 ConstructorElementImpl constructorB =
461 ElementFactory.constructorElement2(classB, '', []); 676 ElementFactory.constructorElement2(classB, '', []);
462 constructorB.setModifier(Modifier.SYNTHETIC, true); 677 constructorB.setModifier(Modifier.SYNTHETIC, true);
463 classB.constructors = [constructorB]; 678 classB.constructors = [constructorB];
464 ClassElement classM = ElementFactory.classElement2('M', []); 679 ClassElement classM = ElementFactory.classElement2('M', []);
465 WithClause withClause = 680 WithClause withClause =
466 AstFactory.withClause([AstFactory.typeName(classM, [])]); 681 AstFactory.withClause([AstFactory.typeName(classM, [])]);
467 ClassTypeAlias alias = AstFactory.classTypeAlias( 682 ClassTypeAlias alias = AstFactory.classTypeAlias(
468 'C', null, null, AstFactory.typeName(classB, []), withClause, null); 683 'C', null, null, AstFactory.typeName(classB, []), withClause, null);
469 alias.accept(builder); 684 alias.accept(builder);
470 List<ClassElement> types = holder.types; 685 List<ClassElement> types = holder.types;
471 expect(types, hasLength(1)); 686 expect(types, hasLength(1));
472 ClassElement type = types[0]; 687 ClassElement type = types[0];
473 expect(alias.element, same(type)); 688 expect(alias.element, same(type));
474 expect(type.name, equals('C')); 689 expect(type.name, equals('C'));
475 expect(type.isAbstract, isFalse); 690 expect(type.isAbstract, isFalse);
476 expect(type.isMixinApplication, isTrue); 691 expect(type.isMixinApplication, isTrue);
477 expect(type.isSynthetic, isFalse); 692 expect(type.isSynthetic, isFalse);
478 expect(type.typeParameters, isEmpty); 693 expect(type.typeParameters, isEmpty);
479 expect(type.fields, isEmpty); 694 expect(type.fields, isEmpty);
480 expect(type.methods, isEmpty); 695 expect(type.methods, isEmpty);
481 } 696 }
482 697
483 void test_visitClassTypeAlias_abstract() { 698 void test_visitClassTypeAlias_abstract() {
484 // class B {} 699 // class B {}
485 // class M {} 700 // class M {}
486 // abstract class C = B with M 701 // abstract class C = B with M
487 ElementHolder holder = new ElementHolder(); 702 ElementHolder holder = new ElementHolder();
488 ElementBuilder builder = new ElementBuilder(holder); 703 ElementBuilder builder = _makeBuilder(holder);
489 ClassElementImpl classB = ElementFactory.classElement2('B', []); 704 ClassElementImpl classB = ElementFactory.classElement2('B', []);
490 ConstructorElementImpl constructorB = 705 ConstructorElementImpl constructorB =
491 ElementFactory.constructorElement2(classB, '', []); 706 ElementFactory.constructorElement2(classB, '', []);
492 constructorB.setModifier(Modifier.SYNTHETIC, true); 707 constructorB.setModifier(Modifier.SYNTHETIC, true);
493 classB.constructors = [constructorB]; 708 classB.constructors = [constructorB];
494 ClassElement classM = ElementFactory.classElement2('M', []); 709 ClassElement classM = ElementFactory.classElement2('M', []);
495 WithClause withClause = 710 WithClause withClause =
496 AstFactory.withClause([AstFactory.typeName(classM, [])]); 711 AstFactory.withClause([AstFactory.typeName(classM, [])]);
497 ClassTypeAlias classCAst = AstFactory.classTypeAlias('C', null, 712 ClassTypeAlias classCAst = AstFactory.classTypeAlias('C', null,
498 Keyword.ABSTRACT, AstFactory.typeName(classB, []), withClause, null); 713 Keyword.ABSTRACT, AstFactory.typeName(classB, []), withClause, null);
499 classCAst.accept(builder); 714 classCAst.accept(builder);
500 List<ClassElement> types = holder.types; 715 List<ClassElement> types = holder.types;
501 expect(types, hasLength(1)); 716 expect(types, hasLength(1));
502 ClassElement type = types[0]; 717 ClassElement type = types[0];
503 expect(type.isAbstract, isTrue); 718 expect(type.isAbstract, isTrue);
504 expect(type.isMixinApplication, isTrue); 719 expect(type.isMixinApplication, isTrue);
505 } 720 }
506 721
507 void test_visitClassTypeAlias_typeParams() { 722 void test_visitClassTypeAlias_typeParams() {
508 // class B {} 723 // class B {}
509 // class M {} 724 // class M {}
510 // class C<T> = B with M 725 // class C<T> = B with M
511 ElementHolder holder = new ElementHolder(); 726 ElementHolder holder = new ElementHolder();
512 ElementBuilder builder = new ElementBuilder(holder); 727 ElementBuilder builder = _makeBuilder(holder);
513 ClassElementImpl classB = ElementFactory.classElement2('B', []); 728 ClassElementImpl classB = ElementFactory.classElement2('B', []);
514 ConstructorElementImpl constructorB = 729 ConstructorElementImpl constructorB =
515 ElementFactory.constructorElement2(classB, '', []); 730 ElementFactory.constructorElement2(classB, '', []);
516 constructorB.setModifier(Modifier.SYNTHETIC, true); 731 constructorB.setModifier(Modifier.SYNTHETIC, true);
517 classB.constructors = [constructorB]; 732 classB.constructors = [constructorB];
518 ClassElementImpl classM = ElementFactory.classElement2('M', []); 733 ClassElementImpl classM = ElementFactory.classElement2('M', []);
519 WithClause withClause = 734 WithClause withClause =
520 AstFactory.withClause([AstFactory.typeName(classM, [])]); 735 AstFactory.withClause([AstFactory.typeName(classM, [])]);
521 ClassTypeAlias classCAst = AstFactory.classTypeAlias( 736 ClassTypeAlias classCAst = AstFactory.classTypeAlias(
522 'C', 737 'C',
523 AstFactory.typeParameterList(['T']), 738 AstFactory.typeParameterList(['T']),
524 null, 739 null,
525 AstFactory.typeName(classB, []), 740 AstFactory.typeName(classB, []),
526 withClause, 741 withClause,
527 null); 742 null);
528 classCAst.accept(builder); 743 classCAst.accept(builder);
529 List<ClassElement> types = holder.types; 744 List<ClassElement> types = holder.types;
530 expect(types, hasLength(1)); 745 expect(types, hasLength(1));
531 ClassElement type = types[0]; 746 ClassElement type = types[0];
532 expect(type.typeParameters, hasLength(1)); 747 expect(type.typeParameters, hasLength(1));
533 expect(type.typeParameters[0].name, equals('T')); 748 expect(type.typeParameters[0].name, equals('T'));
534 } 749 }
535 750
536 void test_visitConstructorDeclaration_external() { 751 void test_visitConstructorDeclaration_external() {
537 ElementHolder holder = new ElementHolder(); 752 ElementHolder holder = new ElementHolder();
538 ElementBuilder builder = new ElementBuilder(holder); 753 ElementBuilder builder = _makeBuilder(holder);
539 String className = "A"; 754 String className = "A";
540 ConstructorDeclaration constructorDeclaration = 755 ConstructorDeclaration constructorDeclaration =
541 AstFactory.constructorDeclaration2( 756 AstFactory.constructorDeclaration2(
542 null, 757 null,
543 null, 758 null,
544 AstFactory.identifier3(className), 759 AstFactory.identifier3(className),
545 null, 760 null,
546 AstFactory.formalParameterList(), 761 AstFactory.formalParameterList(),
547 null, 762 null,
548 AstFactory.blockFunctionBody2()); 763 AstFactory.blockFunctionBody2());
549 constructorDeclaration.externalKeyword = 764 constructorDeclaration.externalKeyword =
550 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); 765 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL);
551 constructorDeclaration.accept(builder); 766 constructorDeclaration.accept(builder);
552 List<ConstructorElement> constructors = holder.constructors; 767 List<ConstructorElement> constructors = holder.constructors;
553 expect(constructors, hasLength(1)); 768 expect(constructors, hasLength(1));
554 ConstructorElement constructor = constructors[0]; 769 ConstructorElement constructor = constructors[0];
555 expect(constructor, isNotNull); 770 expect(constructor, isNotNull);
556 expect(constructor.isExternal, isTrue); 771 expect(constructor.isExternal, isTrue);
557 expect(constructor.isFactory, isFalse); 772 expect(constructor.isFactory, isFalse);
558 expect(constructor.name, ""); 773 expect(constructor.name, "");
559 expect(constructor.functions, hasLength(0)); 774 expect(constructor.functions, hasLength(0));
560 expect(constructor.labels, hasLength(0)); 775 expect(constructor.labels, hasLength(0));
561 expect(constructor.localVariables, hasLength(0)); 776 expect(constructor.localVariables, hasLength(0));
562 expect(constructor.parameters, hasLength(0)); 777 expect(constructor.parameters, hasLength(0));
563 } 778 }
564 779
565 void test_visitConstructorDeclaration_factory() { 780 void test_visitConstructorDeclaration_factory() {
566 ElementHolder holder = new ElementHolder(); 781 ElementHolder holder = new ElementHolder();
567 ElementBuilder builder = new ElementBuilder(holder); 782 ElementBuilder builder = _makeBuilder(holder);
568 String className = "A"; 783 String className = "A";
569 ConstructorDeclaration constructorDeclaration = 784 ConstructorDeclaration constructorDeclaration =
570 AstFactory.constructorDeclaration2( 785 AstFactory.constructorDeclaration2(
571 null, 786 null,
572 Keyword.FACTORY, 787 Keyword.FACTORY,
573 AstFactory.identifier3(className), 788 AstFactory.identifier3(className),
574 null, 789 null,
575 AstFactory.formalParameterList(), 790 AstFactory.formalParameterList(),
576 null, 791 null,
577 AstFactory.blockFunctionBody2()); 792 AstFactory.blockFunctionBody2());
578 constructorDeclaration.accept(builder); 793 constructorDeclaration.accept(builder);
579 List<ConstructorElement> constructors = holder.constructors; 794 List<ConstructorElement> constructors = holder.constructors;
580 expect(constructors, hasLength(1)); 795 expect(constructors, hasLength(1));
581 ConstructorElement constructor = constructors[0]; 796 ConstructorElement constructor = constructors[0];
582 expect(constructor, isNotNull); 797 expect(constructor, isNotNull);
583 expect(constructor.isExternal, isFalse); 798 expect(constructor.isExternal, isFalse);
584 expect(constructor.isFactory, isTrue); 799 expect(constructor.isFactory, isTrue);
585 expect(constructor.name, ""); 800 expect(constructor.name, "");
586 expect(constructor.functions, hasLength(0)); 801 expect(constructor.functions, hasLength(0));
587 expect(constructor.labels, hasLength(0)); 802 expect(constructor.labels, hasLength(0));
588 expect(constructor.localVariables, hasLength(0)); 803 expect(constructor.localVariables, hasLength(0));
589 expect(constructor.parameters, hasLength(0)); 804 expect(constructor.parameters, hasLength(0));
590 } 805 }
591 806
592 void test_visitConstructorDeclaration_minimal() { 807 void test_visitConstructorDeclaration_minimal() {
593 ElementHolder holder = new ElementHolder(); 808 ElementHolder holder = new ElementHolder();
594 ElementBuilder builder = new ElementBuilder(holder); 809 ElementBuilder builder = _makeBuilder(holder);
595 String className = "A"; 810 String className = "A";
596 ConstructorDeclaration constructorDeclaration = 811 ConstructorDeclaration constructorDeclaration =
597 AstFactory.constructorDeclaration2( 812 AstFactory.constructorDeclaration2(
598 null, 813 null,
599 null, 814 null,
600 AstFactory.identifier3(className), 815 AstFactory.identifier3(className),
601 null, 816 null,
602 AstFactory.formalParameterList(), 817 AstFactory.formalParameterList(),
603 null, 818 null,
604 AstFactory.blockFunctionBody2()); 819 AstFactory.blockFunctionBody2());
(...skipping 11 matching lines...) Expand all
616 expect(constructor.isFactory, isFalse); 831 expect(constructor.isFactory, isFalse);
617 expect(constructor.name, ""); 832 expect(constructor.name, "");
618 expect(constructor.functions, hasLength(0)); 833 expect(constructor.functions, hasLength(0));
619 expect(constructor.labels, hasLength(0)); 834 expect(constructor.labels, hasLength(0));
620 expect(constructor.localVariables, hasLength(0)); 835 expect(constructor.localVariables, hasLength(0));
621 expect(constructor.parameters, hasLength(0)); 836 expect(constructor.parameters, hasLength(0));
622 } 837 }
623 838
624 void test_visitConstructorDeclaration_named() { 839 void test_visitConstructorDeclaration_named() {
625 ElementHolder holder = new ElementHolder(); 840 ElementHolder holder = new ElementHolder();
626 ElementBuilder builder = new ElementBuilder(holder); 841 ElementBuilder builder = _makeBuilder(holder);
627 String className = "A"; 842 String className = "A";
628 String constructorName = "c"; 843 String constructorName = "c";
629 ConstructorDeclaration constructorDeclaration = 844 ConstructorDeclaration constructorDeclaration =
630 AstFactory.constructorDeclaration2( 845 AstFactory.constructorDeclaration2(
631 null, 846 null,
632 null, 847 null,
633 AstFactory.identifier3(className), 848 AstFactory.identifier3(className),
634 constructorName, 849 constructorName,
635 AstFactory.formalParameterList(), 850 AstFactory.formalParameterList(),
636 null, 851 null,
637 AstFactory.blockFunctionBody2()); 852 AstFactory.blockFunctionBody2());
638 constructorDeclaration.accept(builder); 853 constructorDeclaration.accept(builder);
639 List<ConstructorElement> constructors = holder.constructors; 854 List<ConstructorElement> constructors = holder.constructors;
640 expect(constructors, hasLength(1)); 855 expect(constructors, hasLength(1));
641 ConstructorElement constructor = constructors[0]; 856 ConstructorElement constructor = constructors[0];
642 expect(constructor, isNotNull); 857 expect(constructor, isNotNull);
643 expect(constructor.isExternal, isFalse); 858 expect(constructor.isExternal, isFalse);
644 expect(constructor.isFactory, isFalse); 859 expect(constructor.isFactory, isFalse);
645 expect(constructor.name, constructorName); 860 expect(constructor.name, constructorName);
646 expect(constructor.functions, hasLength(0)); 861 expect(constructor.functions, hasLength(0));
647 expect(constructor.labels, hasLength(0)); 862 expect(constructor.labels, hasLength(0));
648 expect(constructor.localVariables, hasLength(0)); 863 expect(constructor.localVariables, hasLength(0));
649 expect(constructor.parameters, hasLength(0)); 864 expect(constructor.parameters, hasLength(0));
650 expect(constructorDeclaration.name.staticElement, same(constructor)); 865 expect(constructorDeclaration.name.staticElement, same(constructor));
651 expect(constructorDeclaration.element, same(constructor)); 866 expect(constructorDeclaration.element, same(constructor));
652 } 867 }
653 868
654 void test_visitConstructorDeclaration_unnamed() { 869 void test_visitConstructorDeclaration_unnamed() {
655 ElementHolder holder = new ElementHolder(); 870 ElementHolder holder = new ElementHolder();
656 ElementBuilder builder = new ElementBuilder(holder); 871 ElementBuilder builder = _makeBuilder(holder);
657 String className = "A"; 872 String className = "A";
658 ConstructorDeclaration constructorDeclaration = 873 ConstructorDeclaration constructorDeclaration =
659 AstFactory.constructorDeclaration2( 874 AstFactory.constructorDeclaration2(
660 null, 875 null,
661 null, 876 null,
662 AstFactory.identifier3(className), 877 AstFactory.identifier3(className),
663 null, 878 null,
664 AstFactory.formalParameterList(), 879 AstFactory.formalParameterList(),
665 null, 880 null,
666 AstFactory.blockFunctionBody2()); 881 AstFactory.blockFunctionBody2());
667 constructorDeclaration.accept(builder); 882 constructorDeclaration.accept(builder);
668 List<ConstructorElement> constructors = holder.constructors; 883 List<ConstructorElement> constructors = holder.constructors;
669 expect(constructors, hasLength(1)); 884 expect(constructors, hasLength(1));
670 ConstructorElement constructor = constructors[0]; 885 ConstructorElement constructor = constructors[0];
671 expect(constructor, isNotNull); 886 expect(constructor, isNotNull);
672 expect(constructor.isExternal, isFalse); 887 expect(constructor.isExternal, isFalse);
673 expect(constructor.isFactory, isFalse); 888 expect(constructor.isFactory, isFalse);
674 expect(constructor.name, ""); 889 expect(constructor.name, "");
675 expect(constructor.functions, hasLength(0)); 890 expect(constructor.functions, hasLength(0));
676 expect(constructor.labels, hasLength(0)); 891 expect(constructor.labels, hasLength(0));
677 expect(constructor.localVariables, hasLength(0)); 892 expect(constructor.localVariables, hasLength(0));
678 expect(constructor.parameters, hasLength(0)); 893 expect(constructor.parameters, hasLength(0));
679 expect(constructorDeclaration.element, same(constructor)); 894 expect(constructorDeclaration.element, same(constructor));
680 } 895 }
681 896
682 void test_visitDeclaredIdentifier_noType() { 897 void test_visitDeclaredIdentifier_noType() {
683 // var i 898 // var i
684 ElementHolder holder = new ElementHolder(); 899 ElementHolder holder = new ElementHolder();
685 ElementBuilder builder = new ElementBuilder(holder); 900 ElementBuilder builder = _makeBuilder(holder);
686 var variableName = 'i'; 901 var variableName = 'i';
687 DeclaredIdentifier identifier = 902 DeclaredIdentifier identifier =
688 AstFactory.declaredIdentifier3(variableName); 903 AstFactory.declaredIdentifier3(variableName);
689 AstFactory.forEachStatement( 904 AstFactory.forEachStatement(
690 identifier, AstFactory.nullLiteral(), AstFactory.emptyStatement()); 905 identifier, AstFactory.nullLiteral(), AstFactory.emptyStatement());
691 identifier.accept(builder); 906 identifier.accept(builder);
692 907
693 List<LocalVariableElement> variables = holder.localVariables; 908 List<LocalVariableElement> variables = holder.localVariables;
694 expect(variables, hasLength(1)); 909 expect(variables, hasLength(1));
695 LocalVariableElement variable = variables[0]; 910 LocalVariableElement variable = variables[0];
696 expect(variable, isNotNull); 911 expect(variable, isNotNull);
697 expect(variable.hasImplicitType, isTrue); 912 expect(variable.hasImplicitType, isTrue);
698 expect(variable.isConst, isFalse); 913 expect(variable.isConst, isFalse);
699 expect(variable.isDeprecated, isFalse); 914 expect(variable.isDeprecated, isFalse);
700 expect(variable.isFinal, isFalse); 915 expect(variable.isFinal, isFalse);
701 expect(variable.isOverride, isFalse); 916 expect(variable.isOverride, isFalse);
702 expect(variable.isPrivate, isFalse); 917 expect(variable.isPrivate, isFalse);
703 expect(variable.isPublic, isTrue); 918 expect(variable.isPublic, isTrue);
704 expect(variable.isSynthetic, isFalse); 919 expect(variable.isSynthetic, isFalse);
705 expect(variable.name, variableName); 920 expect(variable.name, variableName);
706 } 921 }
707 922
708 void test_visitDeclaredIdentifier_type() { 923 void test_visitDeclaredIdentifier_type() {
709 // E i 924 // E i
710 ElementHolder holder = new ElementHolder(); 925 ElementHolder holder = new ElementHolder();
711 ElementBuilder builder = new ElementBuilder(holder); 926 ElementBuilder builder = _makeBuilder(holder);
712 var variableName = 'i'; 927 var variableName = 'i';
713 DeclaredIdentifier identifier = 928 DeclaredIdentifier identifier =
714 AstFactory.declaredIdentifier4(AstFactory.typeName4('E'), variableName); 929 AstFactory.declaredIdentifier4(AstFactory.typeName4('E'), variableName);
715 AstFactory.forEachStatement( 930 AstFactory.forEachStatement(
716 identifier, AstFactory.nullLiteral(), AstFactory.emptyStatement()); 931 identifier, AstFactory.nullLiteral(), AstFactory.emptyStatement());
717 identifier.accept(builder); 932 identifier.accept(builder);
718 933
719 List<LocalVariableElement> variables = holder.localVariables; 934 List<LocalVariableElement> variables = holder.localVariables;
720 expect(variables, hasLength(1)); 935 expect(variables, hasLength(1));
721 LocalVariableElement variable = variables[0]; 936 LocalVariableElement variable = variables[0];
722 expect(variable, isNotNull); 937 expect(variable, isNotNull);
723 expect(variable.hasImplicitType, isFalse); 938 expect(variable.hasImplicitType, isFalse);
724 expect(variable.isConst, isFalse); 939 expect(variable.isConst, isFalse);
725 expect(variable.isDeprecated, isFalse); 940 expect(variable.isDeprecated, isFalse);
726 expect(variable.isFinal, isFalse); 941 expect(variable.isFinal, isFalse);
727 expect(variable.isOverride, isFalse); 942 expect(variable.isOverride, isFalse);
728 expect(variable.isPrivate, isFalse); 943 expect(variable.isPrivate, isFalse);
729 expect(variable.isPublic, isTrue); 944 expect(variable.isPublic, isTrue);
730 expect(variable.isSynthetic, isFalse); 945 expect(variable.isSynthetic, isFalse);
731 expect(variable.name, variableName); 946 expect(variable.name, variableName);
732 } 947 }
733 948
734 void test_visitDefaultFormalParameter_noType() { 949 void test_visitDefaultFormalParameter_noType() {
735 // p = 0 950 // p = 0
736 ElementHolder holder = new ElementHolder(); 951 ElementHolder holder = new ElementHolder();
737 ElementBuilder builder = new ElementBuilder(holder); 952 ElementBuilder builder = _makeBuilder(holder);
738 String parameterName = 'p'; 953 String parameterName = 'p';
739 DefaultFormalParameter formalParameter = 954 DefaultFormalParameter formalParameter =
740 AstFactory.positionalFormalParameter( 955 AstFactory.positionalFormalParameter(
741 AstFactory.simpleFormalParameter3(parameterName), 956 AstFactory.simpleFormalParameter3(parameterName),
742 AstFactory.integer(0)); 957 AstFactory.integer(0));
743 formalParameter.accept(builder); 958 formalParameter.accept(builder);
744 959
745 List<ParameterElement> parameters = holder.parameters; 960 List<ParameterElement> parameters = holder.parameters;
746 expect(parameters, hasLength(1)); 961 expect(parameters, hasLength(1));
747 ParameterElement parameter = parameters[0]; 962 ParameterElement parameter = parameters[0];
748 expect(parameter.hasImplicitType, isTrue); 963 expect(parameter.hasImplicitType, isTrue);
749 expect(parameter.isConst, isFalse); 964 expect(parameter.isConst, isFalse);
750 expect(parameter.isDeprecated, isFalse); 965 expect(parameter.isDeprecated, isFalse);
751 expect(parameter.isFinal, isFalse); 966 expect(parameter.isFinal, isFalse);
752 expect(parameter.isInitializingFormal, isFalse); 967 expect(parameter.isInitializingFormal, isFalse);
753 expect(parameter.isOverride, isFalse); 968 expect(parameter.isOverride, isFalse);
754 expect(parameter.isPrivate, isFalse); 969 expect(parameter.isPrivate, isFalse);
755 expect(parameter.isPublic, isTrue); 970 expect(parameter.isPublic, isTrue);
756 expect(parameter.isSynthetic, isFalse); 971 expect(parameter.isSynthetic, isFalse);
757 expect(parameter.name, parameterName); 972 expect(parameter.name, parameterName);
758 } 973 }
759 974
760 void test_visitDefaultFormalParameter_type() { 975 void test_visitDefaultFormalParameter_type() {
761 // E p = 0 976 // E p = 0
762 ElementHolder holder = new ElementHolder(); 977 ElementHolder holder = new ElementHolder();
763 ElementBuilder builder = new ElementBuilder(holder); 978 ElementBuilder builder = _makeBuilder(holder);
764 String parameterName = 'p'; 979 String parameterName = 'p';
765 DefaultFormalParameter formalParameter = AstFactory.namedFormalParameter( 980 DefaultFormalParameter formalParameter = AstFactory.namedFormalParameter(
766 AstFactory.simpleFormalParameter4( 981 AstFactory.simpleFormalParameter4(
767 AstFactory.typeName4('E'), parameterName), 982 AstFactory.typeName4('E'), parameterName),
768 AstFactory.integer(0)); 983 AstFactory.integer(0));
769 formalParameter.accept(builder); 984 formalParameter.accept(builder);
770 985
771 List<ParameterElement> parameters = holder.parameters; 986 List<ParameterElement> parameters = holder.parameters;
772 expect(parameters, hasLength(1)); 987 expect(parameters, hasLength(1));
773 ParameterElement parameter = parameters[0]; 988 ParameterElement parameter = parameters[0];
774 expect(parameter.hasImplicitType, isFalse); 989 expect(parameter.hasImplicitType, isFalse);
775 expect(parameter.isConst, isFalse); 990 expect(parameter.isConst, isFalse);
776 expect(parameter.isDeprecated, isFalse); 991 expect(parameter.isDeprecated, isFalse);
777 expect(parameter.isFinal, isFalse); 992 expect(parameter.isFinal, isFalse);
778 expect(parameter.isInitializingFormal, isFalse); 993 expect(parameter.isInitializingFormal, isFalse);
779 expect(parameter.isOverride, isFalse); 994 expect(parameter.isOverride, isFalse);
780 expect(parameter.isPrivate, isFalse); 995 expect(parameter.isPrivate, isFalse);
781 expect(parameter.isPublic, isTrue); 996 expect(parameter.isPublic, isTrue);
782 expect(parameter.isSynthetic, isFalse); 997 expect(parameter.isSynthetic, isFalse);
783 expect(parameter.name, parameterName); 998 expect(parameter.name, parameterName);
784 } 999 }
785 1000
786 void test_visitEnumDeclaration() { 1001 void test_visitEnumDeclaration() {
787 ElementHolder holder = new ElementHolder(); 1002 ElementHolder holder = new ElementHolder();
788 ElementBuilder builder = new ElementBuilder(holder); 1003 ElementBuilder builder = _makeBuilder(holder);
789 String enumName = "E"; 1004 String enumName = "E";
790 EnumDeclaration enumDeclaration = 1005 EnumDeclaration enumDeclaration =
791 AstFactory.enumDeclaration2(enumName, ["ONE"]); 1006 AstFactory.enumDeclaration2(enumName, ["ONE"]);
792 enumDeclaration.documentationComment = AstFactory.documentationComment( 1007 enumDeclaration.documentationComment = AstFactory.documentationComment(
793 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); 1008 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []);
794 enumDeclaration.accept(builder); 1009 enumDeclaration.accept(builder);
795 List<ClassElement> enums = holder.enums; 1010 List<ClassElement> enums = holder.enums;
796 expect(enums, hasLength(1)); 1011 expect(enums, hasLength(1));
797 ClassElement enumElement = enums[0]; 1012 ClassElement enumElement = enums[0];
798 expect(enumElement, isNotNull); 1013 expect(enumElement, isNotNull);
799 _assertHasDocRange(enumElement, 50, 7); 1014 _assertHasDocRange(enumElement, 50, 7);
800 expect(enumElement.name, enumName); 1015 expect(enumElement.name, enumName);
801 } 1016 }
802 1017
803 void test_visitFieldDeclaration() { 1018 void test_visitFieldDeclaration() {
804 ElementHolder holder = new ElementHolder(); 1019 ElementHolder holder = new ElementHolder();
805 ElementBuilder builder = new ElementBuilder(holder); 1020 ElementBuilder builder = _makeBuilder(holder);
806 String firstFieldName = "x"; 1021 String firstFieldName = "x";
807 String secondFieldName = "y"; 1022 String secondFieldName = "y";
808 FieldDeclaration fieldDeclaration = 1023 FieldDeclaration fieldDeclaration =
809 AstFactory.fieldDeclaration2(false, null, [ 1024 AstFactory.fieldDeclaration2(false, null, [
810 AstFactory.variableDeclaration(firstFieldName), 1025 AstFactory.variableDeclaration(firstFieldName),
811 AstFactory.variableDeclaration(secondFieldName) 1026 AstFactory.variableDeclaration(secondFieldName)
812 ]); 1027 ]);
813 fieldDeclaration.documentationComment = AstFactory.documentationComment( 1028 fieldDeclaration.documentationComment = AstFactory.documentationComment(
814 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); 1029 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []);
815 fieldDeclaration.accept(builder); 1030 fieldDeclaration.accept(builder);
(...skipping 15 matching lines...) Expand all
831 _assertHasDocRange(secondField, 50, 7); 1046 _assertHasDocRange(secondField, 50, 7);
832 expect(secondField.name, secondFieldName); 1047 expect(secondField.name, secondFieldName);
833 expect(secondField.initializer, isNull); 1048 expect(secondField.initializer, isNull);
834 expect(secondField.isConst, isFalse); 1049 expect(secondField.isConst, isFalse);
835 expect(secondField.isFinal, isFalse); 1050 expect(secondField.isFinal, isFalse);
836 expect(secondField.isSynthetic, isFalse); 1051 expect(secondField.isSynthetic, isFalse);
837 } 1052 }
838 1053
839 void test_visitFieldFormalParameter() { 1054 void test_visitFieldFormalParameter() {
840 ElementHolder holder = new ElementHolder(); 1055 ElementHolder holder = new ElementHolder();
841 ElementBuilder builder = new ElementBuilder(holder); 1056 ElementBuilder builder = _makeBuilder(holder);
842 String parameterName = "p"; 1057 String parameterName = "p";
843 FieldFormalParameter formalParameter = 1058 FieldFormalParameter formalParameter =
844 AstFactory.fieldFormalParameter(null, null, parameterName); 1059 AstFactory.fieldFormalParameter(null, null, parameterName);
845 formalParameter.accept(builder); 1060 formalParameter.accept(builder);
846 List<ParameterElement> parameters = holder.parameters; 1061 List<ParameterElement> parameters = holder.parameters;
847 expect(parameters, hasLength(1)); 1062 expect(parameters, hasLength(1));
848 ParameterElement parameter = parameters[0]; 1063 ParameterElement parameter = parameters[0];
849 expect(parameter, isNotNull); 1064 expect(parameter, isNotNull);
850 expect(parameter.name, parameterName); 1065 expect(parameter.name, parameterName);
851 expect(parameter.initializer, isNull); 1066 expect(parameter.initializer, isNull);
852 expect(parameter.isConst, isFalse); 1067 expect(parameter.isConst, isFalse);
853 expect(parameter.isFinal, isFalse); 1068 expect(parameter.isFinal, isFalse);
854 expect(parameter.isSynthetic, isFalse); 1069 expect(parameter.isSynthetic, isFalse);
855 expect(parameter.parameterKind, ParameterKind.REQUIRED); 1070 expect(parameter.parameterKind, ParameterKind.REQUIRED);
856 expect(parameter.parameters, hasLength(0)); 1071 expect(parameter.parameters, hasLength(0));
857 } 1072 }
858 1073
859 void test_visitFieldFormalParameter_functionTyped() { 1074 void test_visitFieldFormalParameter_functionTyped() {
860 ElementHolder holder = new ElementHolder(); 1075 ElementHolder holder = new ElementHolder();
861 ElementBuilder builder = new ElementBuilder(holder); 1076 ElementBuilder builder = _makeBuilder(holder);
862 String parameterName = "p"; 1077 String parameterName = "p";
863 FieldFormalParameter formalParameter = AstFactory.fieldFormalParameter( 1078 FieldFormalParameter formalParameter = AstFactory.fieldFormalParameter(
864 null, 1079 null,
865 null, 1080 null,
866 parameterName, 1081 parameterName,
867 AstFactory 1082 AstFactory
868 .formalParameterList([AstFactory.simpleFormalParameter3("a")])); 1083 .formalParameterList([AstFactory.simpleFormalParameter3("a")]));
869 formalParameter.accept(builder); 1084 formalParameter.accept(builder);
870 List<ParameterElement> parameters = holder.parameters; 1085 List<ParameterElement> parameters = holder.parameters;
871 expect(parameters, hasLength(1)); 1086 expect(parameters, hasLength(1));
872 ParameterElement parameter = parameters[0]; 1087 ParameterElement parameter = parameters[0];
873 expect(parameter, isNotNull); 1088 expect(parameter, isNotNull);
874 expect(parameter.name, parameterName); 1089 expect(parameter.name, parameterName);
875 expect(parameter.initializer, isNull); 1090 expect(parameter.initializer, isNull);
876 expect(parameter.isConst, isFalse); 1091 expect(parameter.isConst, isFalse);
877 expect(parameter.isFinal, isFalse); 1092 expect(parameter.isFinal, isFalse);
878 expect(parameter.isSynthetic, isFalse); 1093 expect(parameter.isSynthetic, isFalse);
879 expect(parameter.parameterKind, ParameterKind.REQUIRED); 1094 expect(parameter.parameterKind, ParameterKind.REQUIRED);
880 expect(parameter.parameters, hasLength(1)); 1095 expect(parameter.parameters, hasLength(1));
881 } 1096 }
882 1097
883 void test_visitFormalParameterList() { 1098 void test_visitFormalParameterList() {
884 ElementHolder holder = new ElementHolder(); 1099 ElementHolder holder = new ElementHolder();
885 ElementBuilder builder = new ElementBuilder(holder); 1100 ElementBuilder builder = _makeBuilder(holder);
886 String firstParameterName = "a"; 1101 String firstParameterName = "a";
887 String secondParameterName = "b"; 1102 String secondParameterName = "b";
888 FormalParameterList parameterList = AstFactory.formalParameterList([ 1103 FormalParameterList parameterList = AstFactory.formalParameterList([
889 AstFactory.simpleFormalParameter3(firstParameterName), 1104 AstFactory.simpleFormalParameter3(firstParameterName),
890 AstFactory.simpleFormalParameter3(secondParameterName) 1105 AstFactory.simpleFormalParameter3(secondParameterName)
891 ]); 1106 ]);
892 parameterList.accept(builder); 1107 parameterList.accept(builder);
893 List<ParameterElement> parameters = holder.parameters; 1108 List<ParameterElement> parameters = holder.parameters;
894 expect(parameters, hasLength(2)); 1109 expect(parameters, hasLength(2));
895 expect(parameters[0].name, firstParameterName); 1110 expect(parameters[0].name, firstParameterName);
896 expect(parameters[1].name, secondParameterName); 1111 expect(parameters[1].name, secondParameterName);
897 } 1112 }
898 1113
899 void test_visitFunctionDeclaration_external() { 1114 void test_visitFunctionDeclaration_external() {
900 // external f(); 1115 // external f();
901 ElementHolder holder = new ElementHolder(); 1116 ElementHolder holder = new ElementHolder();
902 ElementBuilder builder = new ElementBuilder(holder); 1117 ElementBuilder builder = _makeBuilder(holder);
903 String functionName = "f"; 1118 String functionName = "f";
904 FunctionDeclaration declaration = AstFactory.functionDeclaration( 1119 FunctionDeclaration declaration = AstFactory.functionDeclaration(
905 null, 1120 null,
906 null, 1121 null,
907 functionName, 1122 functionName,
908 AstFactory.functionExpression2( 1123 AstFactory.functionExpression2(
909 AstFactory.formalParameterList(), AstFactory.emptyFunctionBody())); 1124 AstFactory.formalParameterList(), AstFactory.emptyFunctionBody()));
910 declaration.externalKeyword = 1125 declaration.externalKeyword =
911 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); 1126 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL);
912 declaration.accept(builder); 1127 declaration.accept(builder);
913 1128
914 List<FunctionElement> functions = holder.functions; 1129 List<FunctionElement> functions = holder.functions;
915 expect(functions, hasLength(1)); 1130 expect(functions, hasLength(1));
916 FunctionElement function = functions[0]; 1131 FunctionElement function = functions[0];
917 expect(function, isNotNull); 1132 expect(function, isNotNull);
918 expect(function.name, functionName); 1133 expect(function.name, functionName);
919 expect(declaration.element, same(function)); 1134 expect(declaration.element, same(function));
920 expect(declaration.functionExpression.element, same(function)); 1135 expect(declaration.functionExpression.element, same(function));
921 expect(function.hasImplicitReturnType, isTrue); 1136 expect(function.hasImplicitReturnType, isTrue);
922 expect(function.isExternal, isTrue); 1137 expect(function.isExternal, isTrue);
923 expect(function.isSynthetic, isFalse); 1138 expect(function.isSynthetic, isFalse);
924 expect(function.typeParameters, hasLength(0)); 1139 expect(function.typeParameters, hasLength(0));
925 } 1140 }
926 1141
927 void test_visitFunctionDeclaration_getter() { 1142 void test_visitFunctionDeclaration_getter() {
928 // get f() {} 1143 // get f() {}
929 ElementHolder holder = new ElementHolder(); 1144 ElementHolder holder = new ElementHolder();
930 ElementBuilder builder = new ElementBuilder(holder); 1145 ElementBuilder builder = _makeBuilder(holder);
931 String functionName = "f"; 1146 String functionName = "f";
932 FunctionDeclaration declaration = AstFactory.functionDeclaration( 1147 FunctionDeclaration declaration = AstFactory.functionDeclaration(
933 null, 1148 null,
934 Keyword.GET, 1149 Keyword.GET,
935 functionName, 1150 functionName,
936 AstFactory.functionExpression2( 1151 AstFactory.functionExpression2(
937 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2())); 1152 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2()));
938 declaration.documentationComment = AstFactory.documentationComment( 1153 declaration.documentationComment = AstFactory.documentationComment(
939 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); 1154 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []);
940 declaration.accept(builder); 1155 declaration.accept(builder);
(...skipping 14 matching lines...) Expand all
955 expect(accessor.typeParameters, hasLength(0)); 1170 expect(accessor.typeParameters, hasLength(0));
956 PropertyInducingElement variable = accessor.variable; 1171 PropertyInducingElement variable = accessor.variable;
957 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableElement, 1172 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableElement,
958 TopLevelVariableElement, variable); 1173 TopLevelVariableElement, variable);
959 expect(variable.isSynthetic, isTrue); 1174 expect(variable.isSynthetic, isTrue);
960 } 1175 }
961 1176
962 void test_visitFunctionDeclaration_plain() { 1177 void test_visitFunctionDeclaration_plain() {
963 // T f() {} 1178 // T f() {}
964 ElementHolder holder = new ElementHolder(); 1179 ElementHolder holder = new ElementHolder();
965 ElementBuilder builder = new ElementBuilder(holder); 1180 ElementBuilder builder = _makeBuilder(holder);
966 String functionName = "f"; 1181 String functionName = "f";
967 FunctionDeclaration declaration = AstFactory.functionDeclaration( 1182 FunctionDeclaration declaration = AstFactory.functionDeclaration(
968 AstFactory.typeName4('T'), 1183 AstFactory.typeName4('T'),
969 null, 1184 null,
970 functionName, 1185 functionName,
971 AstFactory.functionExpression2( 1186 AstFactory.functionExpression2(
972 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2())); 1187 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2()));
973 declaration.documentationComment = AstFactory.documentationComment( 1188 declaration.documentationComment = AstFactory.documentationComment(
974 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); 1189 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []);
975 declaration.accept(builder); 1190 declaration.accept(builder);
976 1191
977 List<FunctionElement> functions = holder.functions; 1192 List<FunctionElement> functions = holder.functions;
978 expect(functions, hasLength(1)); 1193 expect(functions, hasLength(1));
979 FunctionElement function = functions[0]; 1194 FunctionElement function = functions[0];
980 expect(function, isNotNull); 1195 expect(function, isNotNull);
981 _assertHasDocRange(function, 50, 7); 1196 _assertHasDocRange(function, 50, 7);
982 expect(function.hasImplicitReturnType, isFalse); 1197 expect(function.hasImplicitReturnType, isFalse);
983 expect(function.name, functionName); 1198 expect(function.name, functionName);
984 expect(declaration.element, same(function)); 1199 expect(declaration.element, same(function));
985 expect(declaration.functionExpression.element, same(function)); 1200 expect(declaration.functionExpression.element, same(function));
986 expect(function.isExternal, isFalse); 1201 expect(function.isExternal, isFalse);
987 expect(function.isSynthetic, isFalse); 1202 expect(function.isSynthetic, isFalse);
988 expect(function.typeParameters, hasLength(0)); 1203 expect(function.typeParameters, hasLength(0));
989 } 1204 }
990 1205
991 void test_visitFunctionDeclaration_setter() { 1206 void test_visitFunctionDeclaration_setter() {
992 // set f() {} 1207 // set f() {}
993 ElementHolder holder = new ElementHolder(); 1208 ElementHolder holder = new ElementHolder();
994 ElementBuilder builder = new ElementBuilder(holder); 1209 ElementBuilder builder = _makeBuilder(holder);
995 String functionName = "f"; 1210 String functionName = "f";
996 FunctionDeclaration declaration = AstFactory.functionDeclaration( 1211 FunctionDeclaration declaration = AstFactory.functionDeclaration(
997 null, 1212 null,
998 Keyword.SET, 1213 Keyword.SET,
999 functionName, 1214 functionName,
1000 AstFactory.functionExpression2( 1215 AstFactory.functionExpression2(
1001 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2())); 1216 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2()));
1002 declaration.documentationComment = AstFactory.documentationComment( 1217 declaration.documentationComment = AstFactory.documentationComment(
1003 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); 1218 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []);
1004 declaration.accept(builder); 1219 declaration.accept(builder);
(...skipping 14 matching lines...) Expand all
1019 expect(accessor.typeParameters, hasLength(0)); 1234 expect(accessor.typeParameters, hasLength(0));
1020 PropertyInducingElement variable = accessor.variable; 1235 PropertyInducingElement variable = accessor.variable;
1021 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableElement, 1236 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableElement,
1022 TopLevelVariableElement, variable); 1237 TopLevelVariableElement, variable);
1023 expect(variable.isSynthetic, isTrue); 1238 expect(variable.isSynthetic, isTrue);
1024 } 1239 }
1025 1240
1026 void test_visitFunctionDeclaration_typeParameters() { 1241 void test_visitFunctionDeclaration_typeParameters() {
1027 // f<E>() {} 1242 // f<E>() {}
1028 ElementHolder holder = new ElementHolder(); 1243 ElementHolder holder = new ElementHolder();
1029 ElementBuilder builder = new ElementBuilder(holder); 1244 ElementBuilder builder = _makeBuilder(holder);
1030 String functionName = 'f'; 1245 String functionName = 'f';
1031 String typeParameterName = 'E'; 1246 String typeParameterName = 'E';
1032 FunctionExpression expression = AstFactory.functionExpression3( 1247 FunctionExpression expression = AstFactory.functionExpression3(
1033 AstFactory.typeParameterList([typeParameterName]), 1248 AstFactory.typeParameterList([typeParameterName]),
1034 AstFactory.formalParameterList(), 1249 AstFactory.formalParameterList(),
1035 AstFactory.blockFunctionBody2()); 1250 AstFactory.blockFunctionBody2());
1036 FunctionDeclaration declaration = 1251 FunctionDeclaration declaration =
1037 AstFactory.functionDeclaration(null, null, functionName, expression); 1252 AstFactory.functionDeclaration(null, null, functionName, expression);
1038 declaration.accept(builder); 1253 declaration.accept(builder);
1039 1254
1040 List<FunctionElement> functions = holder.functions; 1255 List<FunctionElement> functions = holder.functions;
1041 expect(functions, hasLength(1)); 1256 expect(functions, hasLength(1));
1042 FunctionElement function = functions[0]; 1257 FunctionElement function = functions[0];
1043 expect(function, isNotNull); 1258 expect(function, isNotNull);
1044 expect(function.hasImplicitReturnType, isTrue); 1259 expect(function.hasImplicitReturnType, isTrue);
1045 expect(function.name, functionName); 1260 expect(function.name, functionName);
1046 expect(function.isExternal, isFalse); 1261 expect(function.isExternal, isFalse);
1047 expect(function.isSynthetic, isFalse); 1262 expect(function.isSynthetic, isFalse);
1048 expect(declaration.element, same(function)); 1263 expect(declaration.element, same(function));
1049 expect(expression.element, same(function)); 1264 expect(expression.element, same(function));
1050 List<TypeParameterElement> typeParameters = function.typeParameters; 1265 List<TypeParameterElement> typeParameters = function.typeParameters;
1051 expect(typeParameters, hasLength(1)); 1266 expect(typeParameters, hasLength(1));
1052 TypeParameterElement typeParameter = typeParameters[0]; 1267 TypeParameterElement typeParameter = typeParameters[0];
1053 expect(typeParameter, isNotNull); 1268 expect(typeParameter, isNotNull);
1054 expect(typeParameter.name, typeParameterName); 1269 expect(typeParameter.name, typeParameterName);
1055 } 1270 }
1056 1271
1057 void test_visitFunctionExpression() { 1272 void test_visitFunctionExpression() {
1058 ElementHolder holder = new ElementHolder(); 1273 ElementHolder holder = new ElementHolder();
1059 ElementBuilder builder = new ElementBuilder(holder); 1274 ElementBuilder builder = _makeBuilder(holder);
1060 FunctionExpression expression = AstFactory.functionExpression2( 1275 FunctionExpression expression = AstFactory.functionExpression2(
1061 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2()); 1276 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2());
1062 expression.accept(builder); 1277 expression.accept(builder);
1063 List<FunctionElement> functions = holder.functions; 1278 List<FunctionElement> functions = holder.functions;
1064 expect(functions, hasLength(1)); 1279 expect(functions, hasLength(1));
1065 FunctionElement function = functions[0]; 1280 FunctionElement function = functions[0];
1066 expect(function, isNotNull); 1281 expect(function, isNotNull);
1067 expect(expression.element, same(function)); 1282 expect(expression.element, same(function));
1068 expect(function.hasImplicitReturnType, isTrue); 1283 expect(function.hasImplicitReturnType, isTrue);
1069 expect(function.isSynthetic, isFalse); 1284 expect(function.isSynthetic, isFalse);
1070 expect(function.typeParameters, hasLength(0)); 1285 expect(function.typeParameters, hasLength(0));
1071 } 1286 }
1072 1287
1073 void test_visitFunctionTypeAlias() { 1288 void test_visitFunctionTypeAlias() {
1074 ElementHolder holder = new ElementHolder(); 1289 ElementHolder holder = new ElementHolder();
1075 ElementBuilder builder = new ElementBuilder(holder); 1290 ElementBuilder builder = _makeBuilder(holder);
1076 String aliasName = "F"; 1291 String aliasName = "F";
1077 String parameterName = "E"; 1292 String parameterName = "E";
1078 FunctionTypeAlias aliasNode = AstFactory.typeAlias( 1293 FunctionTypeAlias aliasNode = AstFactory.typeAlias(
1079 null, aliasName, AstFactory.typeParameterList([parameterName]), null); 1294 null, aliasName, AstFactory.typeParameterList([parameterName]), null);
1080 aliasNode.documentationComment = AstFactory.documentationComment( 1295 aliasNode.documentationComment = AstFactory.documentationComment(
1081 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); 1296 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []);
1082 aliasNode.accept(builder); 1297 aliasNode.accept(builder);
1083 1298
1084 List<FunctionTypeAliasElement> aliases = holder.typeAliases; 1299 List<FunctionTypeAliasElement> aliases = holder.typeAliases;
1085 expect(aliases, hasLength(1)); 1300 expect(aliases, hasLength(1));
1086 FunctionTypeAliasElement alias = aliases[0]; 1301 FunctionTypeAliasElement alias = aliases[0];
1087 expect(alias, isNotNull); 1302 expect(alias, isNotNull);
1088 _assertHasDocRange(alias, 50, 7); 1303 _assertHasDocRange(alias, 50, 7);
1089 expect(alias.name, aliasName); 1304 expect(alias.name, aliasName);
1090 expect(alias.parameters, hasLength(0)); 1305 expect(alias.parameters, hasLength(0));
1091 List<TypeParameterElement> typeParameters = alias.typeParameters; 1306 List<TypeParameterElement> typeParameters = alias.typeParameters;
1092 expect(typeParameters, hasLength(1)); 1307 expect(typeParameters, hasLength(1));
1093 TypeParameterElement typeParameter = typeParameters[0]; 1308 TypeParameterElement typeParameter = typeParameters[0];
1094 expect(typeParameter, isNotNull); 1309 expect(typeParameter, isNotNull);
1095 expect(typeParameter.name, parameterName); 1310 expect(typeParameter.name, parameterName);
1096 } 1311 }
1097 1312
1098 void test_visitFunctionTypedFormalParameter() { 1313 void test_visitFunctionTypedFormalParameter() {
1099 ElementHolder holder = new ElementHolder(); 1314 ElementHolder holder = new ElementHolder();
1100 ElementBuilder builder = new ElementBuilder(holder); 1315 ElementBuilder builder = _makeBuilder(holder);
1101 String parameterName = "p"; 1316 String parameterName = "p";
1102 FunctionTypedFormalParameter formalParameter = 1317 FunctionTypedFormalParameter formalParameter =
1103 AstFactory.functionTypedFormalParameter(null, parameterName); 1318 AstFactory.functionTypedFormalParameter(null, parameterName);
1104 _useParameterInMethod(formalParameter, 100, 110); 1319 _useParameterInMethod(formalParameter, 100, 110);
1105 formalParameter.accept(builder); 1320 formalParameter.accept(builder);
1106 List<ParameterElement> parameters = holder.parameters; 1321 List<ParameterElement> parameters = holder.parameters;
1107 expect(parameters, hasLength(1)); 1322 expect(parameters, hasLength(1));
1108 ParameterElement parameter = parameters[0]; 1323 ParameterElement parameter = parameters[0];
1109 expect(parameter, isNotNull); 1324 expect(parameter, isNotNull);
1110 expect(parameter.name, parameterName); 1325 expect(parameter.name, parameterName);
1111 expect(parameter.initializer, isNull); 1326 expect(parameter.initializer, isNull);
1112 expect(parameter.isConst, isFalse); 1327 expect(parameter.isConst, isFalse);
1113 expect(parameter.isFinal, isFalse); 1328 expect(parameter.isFinal, isFalse);
1114 expect(parameter.isSynthetic, isFalse); 1329 expect(parameter.isSynthetic, isFalse);
1115 expect(parameter.parameterKind, ParameterKind.REQUIRED); 1330 expect(parameter.parameterKind, ParameterKind.REQUIRED);
1116 SourceRange visibleRange = parameter.visibleRange; 1331 SourceRange visibleRange = parameter.visibleRange;
1117 expect(100, visibleRange.offset); 1332 expect(100, visibleRange.offset);
1118 expect(110, visibleRange.end); 1333 expect(110, visibleRange.end);
1119 } 1334 }
1120 1335
1121 void test_visitFunctionTypedFormalParameter_withTypeParameters() { 1336 void test_visitFunctionTypedFormalParameter_withTypeParameters() {
1122 ElementHolder holder = new ElementHolder(); 1337 ElementHolder holder = new ElementHolder();
1123 ElementBuilder builder = new ElementBuilder(holder); 1338 ElementBuilder builder = _makeBuilder(holder);
1124 String parameterName = "p"; 1339 String parameterName = "p";
1125 FunctionTypedFormalParameter formalParameter = 1340 FunctionTypedFormalParameter formalParameter =
1126 AstFactory.functionTypedFormalParameter(null, parameterName); 1341 AstFactory.functionTypedFormalParameter(null, parameterName);
1127 formalParameter.typeParameters = AstFactory.typeParameterList(['F']); 1342 formalParameter.typeParameters = AstFactory.typeParameterList(['F']);
1128 _useParameterInMethod(formalParameter, 100, 110); 1343 _useParameterInMethod(formalParameter, 100, 110);
1129 formalParameter.accept(builder); 1344 formalParameter.accept(builder);
1130 List<ParameterElement> parameters = holder.parameters; 1345 List<ParameterElement> parameters = holder.parameters;
1131 expect(parameters, hasLength(1)); 1346 expect(parameters, hasLength(1));
1132 ParameterElement parameter = parameters[0]; 1347 ParameterElement parameter = parameters[0];
1133 expect(parameter, isNotNull); 1348 expect(parameter, isNotNull);
1134 expect(parameter.name, parameterName); 1349 expect(parameter.name, parameterName);
1135 expect(parameter.initializer, isNull); 1350 expect(parameter.initializer, isNull);
1136 expect(parameter.isConst, isFalse); 1351 expect(parameter.isConst, isFalse);
1137 expect(parameter.isFinal, isFalse); 1352 expect(parameter.isFinal, isFalse);
1138 expect(parameter.isSynthetic, isFalse); 1353 expect(parameter.isSynthetic, isFalse);
1139 expect(parameter.parameterKind, ParameterKind.REQUIRED); 1354 expect(parameter.parameterKind, ParameterKind.REQUIRED);
1140 expect(parameter.typeParameters, hasLength(1)); 1355 expect(parameter.typeParameters, hasLength(1));
1141 SourceRange visibleRange = parameter.visibleRange; 1356 SourceRange visibleRange = parameter.visibleRange;
1142 expect(100, visibleRange.offset); 1357 expect(100, visibleRange.offset);
1143 expect(110, visibleRange.end); 1358 expect(110, visibleRange.end);
1144 } 1359 }
1145 1360
1146 void test_visitLabeledStatement() { 1361 void test_visitLabeledStatement() {
1147 ElementHolder holder = new ElementHolder(); 1362 ElementHolder holder = new ElementHolder();
1148 ElementBuilder builder = new ElementBuilder(holder); 1363 ElementBuilder builder = _makeBuilder(holder);
1149 String labelName = "l"; 1364 String labelName = "l";
1150 LabeledStatement statement = AstFactory.labeledStatement( 1365 LabeledStatement statement = AstFactory.labeledStatement(
1151 [AstFactory.label2(labelName)], AstFactory.breakStatement()); 1366 [AstFactory.label2(labelName)], AstFactory.breakStatement());
1152 statement.accept(builder); 1367 statement.accept(builder);
1153 List<LabelElement> labels = holder.labels; 1368 List<LabelElement> labels = holder.labels;
1154 expect(labels, hasLength(1)); 1369 expect(labels, hasLength(1));
1155 LabelElement label = labels[0]; 1370 LabelElement label = labels[0];
1156 expect(label, isNotNull); 1371 expect(label, isNotNull);
1157 expect(label.name, labelName); 1372 expect(label.name, labelName);
1158 expect(label.isSynthetic, isFalse); 1373 expect(label.isSynthetic, isFalse);
1159 } 1374 }
1160 1375
1161 void test_visitMethodDeclaration_abstract() { 1376 void test_visitMethodDeclaration_abstract() {
1162 // m(); 1377 // m();
1163 ElementHolder holder = new ElementHolder(); 1378 ElementHolder holder = new ElementHolder();
1164 ElementBuilder builder = new ElementBuilder(holder); 1379 ElementBuilder builder = _makeBuilder(holder);
1165 String methodName = "m"; 1380 String methodName = "m";
1166 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( 1381 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2(
1167 null, 1382 null,
1168 null, 1383 null,
1169 null, 1384 null,
1170 null, 1385 null,
1171 AstFactory.identifier3(methodName), 1386 AstFactory.identifier3(methodName),
1172 AstFactory.formalParameterList(), 1387 AstFactory.formalParameterList(),
1173 AstFactory.emptyFunctionBody()); 1388 AstFactory.emptyFunctionBody());
1174 methodDeclaration.accept(builder); 1389 methodDeclaration.accept(builder);
(...skipping 11 matching lines...) Expand all
1186 expect(method.typeParameters, hasLength(0)); 1401 expect(method.typeParameters, hasLength(0));
1187 expect(method.isAbstract, isTrue); 1402 expect(method.isAbstract, isTrue);
1188 expect(method.isExternal, isFalse); 1403 expect(method.isExternal, isFalse);
1189 expect(method.isStatic, isFalse); 1404 expect(method.isStatic, isFalse);
1190 expect(method.isSynthetic, isFalse); 1405 expect(method.isSynthetic, isFalse);
1191 } 1406 }
1192 1407
1193 void test_visitMethodDeclaration_external() { 1408 void test_visitMethodDeclaration_external() {
1194 // external m(); 1409 // external m();
1195 ElementHolder holder = new ElementHolder(); 1410 ElementHolder holder = new ElementHolder();
1196 ElementBuilder builder = new ElementBuilder(holder); 1411 ElementBuilder builder = _makeBuilder(holder);
1197 String methodName = "m"; 1412 String methodName = "m";
1198 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( 1413 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2(
1199 null, 1414 null,
1200 null, 1415 null,
1201 null, 1416 null,
1202 null, 1417 null,
1203 AstFactory.identifier3(methodName), 1418 AstFactory.identifier3(methodName),
1204 AstFactory.formalParameterList(), 1419 AstFactory.formalParameterList(),
1205 AstFactory.emptyFunctionBody()); 1420 AstFactory.emptyFunctionBody());
1206 methodDeclaration.externalKeyword = 1421 methodDeclaration.externalKeyword =
(...skipping 13 matching lines...) Expand all
1220 expect(method.typeParameters, hasLength(0)); 1435 expect(method.typeParameters, hasLength(0));
1221 expect(method.isAbstract, isFalse); 1436 expect(method.isAbstract, isFalse);
1222 expect(method.isExternal, isTrue); 1437 expect(method.isExternal, isTrue);
1223 expect(method.isStatic, isFalse); 1438 expect(method.isStatic, isFalse);
1224 expect(method.isSynthetic, isFalse); 1439 expect(method.isSynthetic, isFalse);
1225 } 1440 }
1226 1441
1227 void test_visitMethodDeclaration_getter() { 1442 void test_visitMethodDeclaration_getter() {
1228 // get m() {} 1443 // get m() {}
1229 ElementHolder holder = new ElementHolder(); 1444 ElementHolder holder = new ElementHolder();
1230 ElementBuilder builder = new ElementBuilder(holder); 1445 ElementBuilder builder = _makeBuilder(holder);
1231 String methodName = "m"; 1446 String methodName = "m";
1232 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( 1447 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2(
1233 null, 1448 null,
1234 null, 1449 null,
1235 Keyword.GET, 1450 Keyword.GET,
1236 null, 1451 null,
1237 AstFactory.identifier3(methodName), 1452 AstFactory.identifier3(methodName),
1238 AstFactory.formalParameterList(), 1453 AstFactory.formalParameterList(),
1239 AstFactory.blockFunctionBody2()); 1454 AstFactory.blockFunctionBody2());
1240 methodDeclaration.documentationComment = AstFactory.documentationComment( 1455 methodDeclaration.documentationComment = AstFactory.documentationComment(
(...skipping 19 matching lines...) Expand all
1260 expect(getter.variable, field); 1475 expect(getter.variable, field);
1261 expect(getter.functions, hasLength(0)); 1476 expect(getter.functions, hasLength(0));
1262 expect(getter.labels, hasLength(0)); 1477 expect(getter.labels, hasLength(0));
1263 expect(getter.localVariables, hasLength(0)); 1478 expect(getter.localVariables, hasLength(0));
1264 expect(getter.parameters, hasLength(0)); 1479 expect(getter.parameters, hasLength(0));
1265 } 1480 }
1266 1481
1267 void test_visitMethodDeclaration_getter_abstract() { 1482 void test_visitMethodDeclaration_getter_abstract() {
1268 // get m(); 1483 // get m();
1269 ElementHolder holder = new ElementHolder(); 1484 ElementHolder holder = new ElementHolder();
1270 ElementBuilder builder = new ElementBuilder(holder); 1485 ElementBuilder builder = _makeBuilder(holder);
1271 String methodName = "m"; 1486 String methodName = "m";
1272 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( 1487 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2(
1273 null, 1488 null,
1274 null, 1489 null,
1275 Keyword.GET, 1490 Keyword.GET,
1276 null, 1491 null,
1277 AstFactory.identifier3(methodName), 1492 AstFactory.identifier3(methodName),
1278 AstFactory.formalParameterList(), 1493 AstFactory.formalParameterList(),
1279 AstFactory.emptyFunctionBody()); 1494 AstFactory.emptyFunctionBody());
1280 methodDeclaration.accept(builder); 1495 methodDeclaration.accept(builder);
(...skipping 16 matching lines...) Expand all
1297 expect(getter.variable, field); 1512 expect(getter.variable, field);
1298 expect(getter.functions, hasLength(0)); 1513 expect(getter.functions, hasLength(0));
1299 expect(getter.labels, hasLength(0)); 1514 expect(getter.labels, hasLength(0));
1300 expect(getter.localVariables, hasLength(0)); 1515 expect(getter.localVariables, hasLength(0));
1301 expect(getter.parameters, hasLength(0)); 1516 expect(getter.parameters, hasLength(0));
1302 } 1517 }
1303 1518
1304 void test_visitMethodDeclaration_getter_external() { 1519 void test_visitMethodDeclaration_getter_external() {
1305 // external get m(); 1520 // external get m();
1306 ElementHolder holder = new ElementHolder(); 1521 ElementHolder holder = new ElementHolder();
1307 ElementBuilder builder = new ElementBuilder(holder); 1522 ElementBuilder builder = _makeBuilder(holder);
1308 String methodName = "m"; 1523 String methodName = "m";
1309 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration( 1524 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration(
1310 null, 1525 null,
1311 null, 1526 null,
1312 Keyword.GET, 1527 Keyword.GET,
1313 null, 1528 null,
1314 AstFactory.identifier3(methodName), 1529 AstFactory.identifier3(methodName),
1315 AstFactory.formalParameterList()); 1530 AstFactory.formalParameterList());
1316 methodDeclaration.externalKeyword = 1531 methodDeclaration.externalKeyword =
1317 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); 1532 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL);
(...skipping 17 matching lines...) Expand all
1335 expect(getter.variable, field); 1550 expect(getter.variable, field);
1336 expect(getter.functions, hasLength(0)); 1551 expect(getter.functions, hasLength(0));
1337 expect(getter.labels, hasLength(0)); 1552 expect(getter.labels, hasLength(0));
1338 expect(getter.localVariables, hasLength(0)); 1553 expect(getter.localVariables, hasLength(0));
1339 expect(getter.parameters, hasLength(0)); 1554 expect(getter.parameters, hasLength(0));
1340 } 1555 }
1341 1556
1342 void test_visitMethodDeclaration_minimal() { 1557 void test_visitMethodDeclaration_minimal() {
1343 // T m() {} 1558 // T m() {}
1344 ElementHolder holder = new ElementHolder(); 1559 ElementHolder holder = new ElementHolder();
1345 ElementBuilder builder = new ElementBuilder(holder); 1560 ElementBuilder builder = _makeBuilder(holder);
1346 String methodName = "m"; 1561 String methodName = "m";
1347 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( 1562 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2(
1348 null, 1563 null,
1349 AstFactory.typeName4('T'), 1564 AstFactory.typeName4('T'),
1350 null, 1565 null,
1351 null, 1566 null,
1352 AstFactory.identifier3(methodName), 1567 AstFactory.identifier3(methodName),
1353 AstFactory.formalParameterList(), 1568 AstFactory.formalParameterList(),
1354 AstFactory.blockFunctionBody2()); 1569 AstFactory.blockFunctionBody2());
1355 methodDeclaration.documentationComment = AstFactory.documentationComment( 1570 methodDeclaration.documentationComment = AstFactory.documentationComment(
(...skipping 14 matching lines...) Expand all
1370 expect(method.typeParameters, hasLength(0)); 1585 expect(method.typeParameters, hasLength(0));
1371 expect(method.isAbstract, isFalse); 1586 expect(method.isAbstract, isFalse);
1372 expect(method.isExternal, isFalse); 1587 expect(method.isExternal, isFalse);
1373 expect(method.isStatic, isFalse); 1588 expect(method.isStatic, isFalse);
1374 expect(method.isSynthetic, isFalse); 1589 expect(method.isSynthetic, isFalse);
1375 } 1590 }
1376 1591
1377 void test_visitMethodDeclaration_operator() { 1592 void test_visitMethodDeclaration_operator() {
1378 // operator +(addend) {} 1593 // operator +(addend) {}
1379 ElementHolder holder = new ElementHolder(); 1594 ElementHolder holder = new ElementHolder();
1380 ElementBuilder builder = new ElementBuilder(holder); 1595 ElementBuilder builder = _makeBuilder(holder);
1381 String methodName = "+"; 1596 String methodName = "+";
1382 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( 1597 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2(
1383 null, 1598 null,
1384 null, 1599 null,
1385 null, 1600 null,
1386 Keyword.OPERATOR, 1601 Keyword.OPERATOR,
1387 AstFactory.identifier3(methodName), 1602 AstFactory.identifier3(methodName),
1388 AstFactory 1603 AstFactory
1389 .formalParameterList([AstFactory.simpleFormalParameter3("addend")]), 1604 .formalParameterList([AstFactory.simpleFormalParameter3("addend")]),
1390 AstFactory.blockFunctionBody2()); 1605 AstFactory.blockFunctionBody2());
(...skipping 12 matching lines...) Expand all
1403 expect(method.typeParameters, hasLength(0)); 1618 expect(method.typeParameters, hasLength(0));
1404 expect(method.isAbstract, isFalse); 1619 expect(method.isAbstract, isFalse);
1405 expect(method.isExternal, isFalse); 1620 expect(method.isExternal, isFalse);
1406 expect(method.isStatic, isFalse); 1621 expect(method.isStatic, isFalse);
1407 expect(method.isSynthetic, isFalse); 1622 expect(method.isSynthetic, isFalse);
1408 } 1623 }
1409 1624
1410 void test_visitMethodDeclaration_setter() { 1625 void test_visitMethodDeclaration_setter() {
1411 // set m() {} 1626 // set m() {}
1412 ElementHolder holder = new ElementHolder(); 1627 ElementHolder holder = new ElementHolder();
1413 ElementBuilder builder = new ElementBuilder(holder); 1628 ElementBuilder builder = _makeBuilder(holder);
1414 String methodName = "m"; 1629 String methodName = "m";
1415 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( 1630 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2(
1416 null, 1631 null,
1417 null, 1632 null,
1418 Keyword.SET, 1633 Keyword.SET,
1419 null, 1634 null,
1420 AstFactory.identifier3(methodName), 1635 AstFactory.identifier3(methodName),
1421 AstFactory.formalParameterList(), 1636 AstFactory.formalParameterList(),
1422 AstFactory.blockFunctionBody2()); 1637 AstFactory.blockFunctionBody2());
1423 methodDeclaration.documentationComment = AstFactory.documentationComment( 1638 methodDeclaration.documentationComment = AstFactory.documentationComment(
(...skipping 21 matching lines...) Expand all
1445 expect(setter.variable, field); 1660 expect(setter.variable, field);
1446 expect(setter.functions, hasLength(0)); 1661 expect(setter.functions, hasLength(0));
1447 expect(setter.labels, hasLength(0)); 1662 expect(setter.labels, hasLength(0));
1448 expect(setter.localVariables, hasLength(0)); 1663 expect(setter.localVariables, hasLength(0));
1449 expect(setter.parameters, hasLength(0)); 1664 expect(setter.parameters, hasLength(0));
1450 } 1665 }
1451 1666
1452 void test_visitMethodDeclaration_setter_abstract() { 1667 void test_visitMethodDeclaration_setter_abstract() {
1453 // set m(); 1668 // set m();
1454 ElementHolder holder = new ElementHolder(); 1669 ElementHolder holder = new ElementHolder();
1455 ElementBuilder builder = new ElementBuilder(holder); 1670 ElementBuilder builder = _makeBuilder(holder);
1456 String methodName = "m"; 1671 String methodName = "m";
1457 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( 1672 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2(
1458 null, 1673 null,
1459 null, 1674 null,
1460 Keyword.SET, 1675 Keyword.SET,
1461 null, 1676 null,
1462 AstFactory.identifier3(methodName), 1677 AstFactory.identifier3(methodName),
1463 AstFactory.formalParameterList(), 1678 AstFactory.formalParameterList(),
1464 AstFactory.emptyFunctionBody()); 1679 AstFactory.emptyFunctionBody());
1465 methodDeclaration.accept(builder); 1680 methodDeclaration.accept(builder);
(...skipping 17 matching lines...) Expand all
1483 expect(setter.variable, field); 1698 expect(setter.variable, field);
1484 expect(setter.functions, hasLength(0)); 1699 expect(setter.functions, hasLength(0));
1485 expect(setter.labels, hasLength(0)); 1700 expect(setter.labels, hasLength(0));
1486 expect(setter.localVariables, hasLength(0)); 1701 expect(setter.localVariables, hasLength(0));
1487 expect(setter.parameters, hasLength(0)); 1702 expect(setter.parameters, hasLength(0));
1488 } 1703 }
1489 1704
1490 void test_visitMethodDeclaration_setter_external() { 1705 void test_visitMethodDeclaration_setter_external() {
1491 // external m(); 1706 // external m();
1492 ElementHolder holder = new ElementHolder(); 1707 ElementHolder holder = new ElementHolder();
1493 ElementBuilder builder = new ElementBuilder(holder); 1708 ElementBuilder builder = _makeBuilder(holder);
1494 String methodName = "m"; 1709 String methodName = "m";
1495 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration( 1710 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration(
1496 null, 1711 null,
1497 null, 1712 null,
1498 Keyword.SET, 1713 Keyword.SET,
1499 null, 1714 null,
1500 AstFactory.identifier3(methodName), 1715 AstFactory.identifier3(methodName),
1501 AstFactory.formalParameterList()); 1716 AstFactory.formalParameterList());
1502 methodDeclaration.externalKeyword = 1717 methodDeclaration.externalKeyword =
1503 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); 1718 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL);
(...skipping 18 matching lines...) Expand all
1522 expect(setter.variable, field); 1737 expect(setter.variable, field);
1523 expect(setter.functions, hasLength(0)); 1738 expect(setter.functions, hasLength(0));
1524 expect(setter.labels, hasLength(0)); 1739 expect(setter.labels, hasLength(0));
1525 expect(setter.localVariables, hasLength(0)); 1740 expect(setter.localVariables, hasLength(0));
1526 expect(setter.parameters, hasLength(0)); 1741 expect(setter.parameters, hasLength(0));
1527 } 1742 }
1528 1743
1529 void test_visitMethodDeclaration_static() { 1744 void test_visitMethodDeclaration_static() {
1530 // static m() {} 1745 // static m() {}
1531 ElementHolder holder = new ElementHolder(); 1746 ElementHolder holder = new ElementHolder();
1532 ElementBuilder builder = new ElementBuilder(holder); 1747 ElementBuilder builder = _makeBuilder(holder);
1533 String methodName = "m"; 1748 String methodName = "m";
1534 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( 1749 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2(
1535 Keyword.STATIC, 1750 Keyword.STATIC,
1536 null, 1751 null,
1537 null, 1752 null,
1538 null, 1753 null,
1539 AstFactory.identifier3(methodName), 1754 AstFactory.identifier3(methodName),
1540 AstFactory.formalParameterList(), 1755 AstFactory.formalParameterList(),
1541 AstFactory.blockFunctionBody2()); 1756 AstFactory.blockFunctionBody2());
1542 methodDeclaration.accept(builder); 1757 methodDeclaration.accept(builder);
(...skipping 10 matching lines...) Expand all
1553 expect(method.typeParameters, hasLength(0)); 1768 expect(method.typeParameters, hasLength(0));
1554 expect(method.isAbstract, isFalse); 1769 expect(method.isAbstract, isFalse);
1555 expect(method.isExternal, isFalse); 1770 expect(method.isExternal, isFalse);
1556 expect(method.isStatic, isTrue); 1771 expect(method.isStatic, isTrue);
1557 expect(method.isSynthetic, isFalse); 1772 expect(method.isSynthetic, isFalse);
1558 } 1773 }
1559 1774
1560 void test_visitMethodDeclaration_typeParameters() { 1775 void test_visitMethodDeclaration_typeParameters() {
1561 // m<E>() {} 1776 // m<E>() {}
1562 ElementHolder holder = new ElementHolder(); 1777 ElementHolder holder = new ElementHolder();
1563 ElementBuilder builder = new ElementBuilder(holder); 1778 ElementBuilder builder = _makeBuilder(holder);
1564 String methodName = "m"; 1779 String methodName = "m";
1565 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( 1780 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2(
1566 null, 1781 null,
1567 null, 1782 null,
1568 null, 1783 null,
1569 null, 1784 null,
1570 AstFactory.identifier3(methodName), 1785 AstFactory.identifier3(methodName),
1571 AstFactory.formalParameterList(), 1786 AstFactory.formalParameterList(),
1572 AstFactory.blockFunctionBody2()); 1787 AstFactory.blockFunctionBody2());
1573 methodDeclaration.typeParameters = AstFactory.typeParameterList(['E']); 1788 methodDeclaration.typeParameters = AstFactory.typeParameterList(['E']);
(...skipping 12 matching lines...) Expand all
1586 expect(method.typeParameters, hasLength(1)); 1801 expect(method.typeParameters, hasLength(1));
1587 expect(method.isAbstract, isFalse); 1802 expect(method.isAbstract, isFalse);
1588 expect(method.isExternal, isFalse); 1803 expect(method.isExternal, isFalse);
1589 expect(method.isStatic, isFalse); 1804 expect(method.isStatic, isFalse);
1590 expect(method.isSynthetic, isFalse); 1805 expect(method.isSynthetic, isFalse);
1591 } 1806 }
1592 1807
1593 void test_visitMethodDeclaration_withMembers() { 1808 void test_visitMethodDeclaration_withMembers() {
1594 // m(p) { var v; try { l: return; } catch (e) {} } 1809 // m(p) { var v; try { l: return; } catch (e) {} }
1595 ElementHolder holder = new ElementHolder(); 1810 ElementHolder holder = new ElementHolder();
1596 ElementBuilder builder = new ElementBuilder(holder); 1811 ElementBuilder builder = _makeBuilder(holder);
1597 String methodName = "m"; 1812 String methodName = "m";
1598 String parameterName = "p"; 1813 String parameterName = "p";
1599 String localVariableName = "v"; 1814 String localVariableName = "v";
1600 String labelName = "l"; 1815 String labelName = "l";
1601 String exceptionParameterName = "e"; 1816 String exceptionParameterName = "e";
1602 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( 1817 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2(
1603 null, 1818 null,
1604 null, 1819 null,
1605 null, 1820 null,
1606 null, 1821 null,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1649 isTrue); 1864 isTrue);
1650 List<LabelElement> labels = method.labels; 1865 List<LabelElement> labels = method.labels;
1651 expect(labels, hasLength(1)); 1866 expect(labels, hasLength(1));
1652 LabelElement label = labels[0]; 1867 LabelElement label = labels[0];
1653 expect(label, isNotNull); 1868 expect(label, isNotNull);
1654 expect(label.name, labelName); 1869 expect(label.name, labelName);
1655 } 1870 }
1656 1871
1657 void test_visitNamedFormalParameter() { 1872 void test_visitNamedFormalParameter() {
1658 ElementHolder holder = new ElementHolder(); 1873 ElementHolder holder = new ElementHolder();
1659 ElementBuilder builder = new ElementBuilder(holder); 1874 ElementBuilder builder = _makeBuilder(holder);
1660 String parameterName = "p"; 1875 String parameterName = "p";
1661 DefaultFormalParameter formalParameter = AstFactory.namedFormalParameter( 1876 DefaultFormalParameter formalParameter = AstFactory.namedFormalParameter(
1662 AstFactory.simpleFormalParameter3(parameterName), 1877 AstFactory.simpleFormalParameter3(parameterName),
1663 AstFactory.identifier3("42")); 1878 AstFactory.identifier3("42"));
1664 _useParameterInMethod(formalParameter, 100, 110); 1879 _useParameterInMethod(formalParameter, 100, 110);
1665 formalParameter.accept(builder); 1880 formalParameter.accept(builder);
1666 List<ParameterElement> parameters = holder.parameters; 1881 List<ParameterElement> parameters = holder.parameters;
1667 expect(parameters, hasLength(1)); 1882 expect(parameters, hasLength(1));
1668 ParameterElement parameter = parameters[0]; 1883 ParameterElement parameter = parameters[0];
1669 expect(parameter, isNotNull); 1884 expect(parameter, isNotNull);
1670 expect(parameter.name, parameterName); 1885 expect(parameter.name, parameterName);
1671 expect(parameter.isConst, isFalse); 1886 expect(parameter.isConst, isFalse);
1672 expect(parameter.isFinal, isFalse); 1887 expect(parameter.isFinal, isFalse);
1673 expect(parameter.isSynthetic, isFalse); 1888 expect(parameter.isSynthetic, isFalse);
1674 expect(parameter.parameterKind, ParameterKind.NAMED); 1889 expect(parameter.parameterKind, ParameterKind.NAMED);
1675 { 1890 {
1676 SourceRange visibleRange = parameter.visibleRange; 1891 SourceRange visibleRange = parameter.visibleRange;
1677 expect(100, visibleRange.offset); 1892 expect(100, visibleRange.offset);
1678 expect(110, visibleRange.end); 1893 expect(110, visibleRange.end);
1679 } 1894 }
1680 expect(parameter.defaultValueCode, "42"); 1895 expect(parameter.defaultValueCode, "42");
1681 FunctionElement initializer = parameter.initializer; 1896 FunctionElement initializer = parameter.initializer;
1682 expect(initializer, isNotNull); 1897 expect(initializer, isNotNull);
1683 expect(initializer.isSynthetic, isTrue); 1898 expect(initializer.isSynthetic, isTrue);
1684 } 1899 }
1685 1900
1686 void test_visitSimpleFormalParameter_noType() { 1901 void test_visitSimpleFormalParameter_noType() {
1687 // p 1902 // p
1688 ElementHolder holder = new ElementHolder(); 1903 ElementHolder holder = new ElementHolder();
1689 ElementBuilder builder = new ElementBuilder(holder); 1904 ElementBuilder builder = _makeBuilder(holder);
1690 String parameterName = "p"; 1905 String parameterName = "p";
1691 SimpleFormalParameter formalParameter = 1906 SimpleFormalParameter formalParameter =
1692 AstFactory.simpleFormalParameter3(parameterName); 1907 AstFactory.simpleFormalParameter3(parameterName);
1693 _useParameterInMethod(formalParameter, 100, 110); 1908 _useParameterInMethod(formalParameter, 100, 110);
1694 formalParameter.accept(builder); 1909 formalParameter.accept(builder);
1695 List<ParameterElement> parameters = holder.parameters; 1910 List<ParameterElement> parameters = holder.parameters;
1696 expect(parameters, hasLength(1)); 1911 expect(parameters, hasLength(1));
1697 ParameterElement parameter = parameters[0]; 1912 ParameterElement parameter = parameters[0];
1698 expect(parameter, isNotNull); 1913 expect(parameter, isNotNull);
1699 expect(parameter.hasImplicitType, isTrue); 1914 expect(parameter.hasImplicitType, isTrue);
1700 expect(parameter.initializer, isNull); 1915 expect(parameter.initializer, isNull);
1701 expect(parameter.isConst, isFalse); 1916 expect(parameter.isConst, isFalse);
1702 expect(parameter.isFinal, isFalse); 1917 expect(parameter.isFinal, isFalse);
1703 expect(parameter.isSynthetic, isFalse); 1918 expect(parameter.isSynthetic, isFalse);
1704 expect(parameter.name, parameterName); 1919 expect(parameter.name, parameterName);
1705 expect(parameter.parameterKind, ParameterKind.REQUIRED); 1920 expect(parameter.parameterKind, ParameterKind.REQUIRED);
1706 { 1921 {
1707 SourceRange visibleRange = parameter.visibleRange; 1922 SourceRange visibleRange = parameter.visibleRange;
1708 expect(100, visibleRange.offset); 1923 expect(100, visibleRange.offset);
1709 expect(110, visibleRange.end); 1924 expect(110, visibleRange.end);
1710 } 1925 }
1711 } 1926 }
1712 1927
1713 void test_visitSimpleFormalParameter_type() { 1928 void test_visitSimpleFormalParameter_type() {
1714 // T p 1929 // T p
1715 ElementHolder holder = new ElementHolder(); 1930 ElementHolder holder = new ElementHolder();
1716 ElementBuilder builder = new ElementBuilder(holder); 1931 ElementBuilder builder = _makeBuilder(holder);
1717 String parameterName = "p"; 1932 String parameterName = "p";
1718 SimpleFormalParameter formalParameter = AstFactory.simpleFormalParameter4( 1933 SimpleFormalParameter formalParameter = AstFactory.simpleFormalParameter4(
1719 AstFactory.typeName4('T'), parameterName); 1934 AstFactory.typeName4('T'), parameterName);
1720 _useParameterInMethod(formalParameter, 100, 110); 1935 _useParameterInMethod(formalParameter, 100, 110);
1721 formalParameter.accept(builder); 1936 formalParameter.accept(builder);
1722 List<ParameterElement> parameters = holder.parameters; 1937 List<ParameterElement> parameters = holder.parameters;
1723 expect(parameters, hasLength(1)); 1938 expect(parameters, hasLength(1));
1724 ParameterElement parameter = parameters[0]; 1939 ParameterElement parameter = parameters[0];
1725 expect(parameter, isNotNull); 1940 expect(parameter, isNotNull);
1726 expect(parameter.hasImplicitType, isFalse); 1941 expect(parameter.hasImplicitType, isFalse);
1727 expect(parameter.initializer, isNull); 1942 expect(parameter.initializer, isNull);
1728 expect(parameter.isConst, isFalse); 1943 expect(parameter.isConst, isFalse);
1729 expect(parameter.isFinal, isFalse); 1944 expect(parameter.isFinal, isFalse);
1730 expect(parameter.isSynthetic, isFalse); 1945 expect(parameter.isSynthetic, isFalse);
1731 expect(parameter.name, parameterName); 1946 expect(parameter.name, parameterName);
1732 expect(parameter.parameterKind, ParameterKind.REQUIRED); 1947 expect(parameter.parameterKind, ParameterKind.REQUIRED);
1733 { 1948 {
1734 SourceRange visibleRange = parameter.visibleRange; 1949 SourceRange visibleRange = parameter.visibleRange;
1735 expect(100, visibleRange.offset); 1950 expect(100, visibleRange.offset);
1736 expect(110, visibleRange.end); 1951 expect(110, visibleRange.end);
1737 } 1952 }
1738 } 1953 }
1739 1954
1740 void test_visitTypeAlias_minimal() { 1955 void test_visitTypeAlias_minimal() {
1741 ElementHolder holder = new ElementHolder(); 1956 ElementHolder holder = new ElementHolder();
1742 ElementBuilder builder = new ElementBuilder(holder); 1957 ElementBuilder builder = _makeBuilder(holder);
1743 String aliasName = "F"; 1958 String aliasName = "F";
1744 TypeAlias typeAlias = AstFactory.typeAlias(null, aliasName, null, null); 1959 TypeAlias typeAlias = AstFactory.typeAlias(null, aliasName, null, null);
1745 typeAlias.accept(builder); 1960 typeAlias.accept(builder);
1746 List<FunctionTypeAliasElement> aliases = holder.typeAliases; 1961 List<FunctionTypeAliasElement> aliases = holder.typeAliases;
1747 expect(aliases, hasLength(1)); 1962 expect(aliases, hasLength(1));
1748 FunctionTypeAliasElement alias = aliases[0]; 1963 FunctionTypeAliasElement alias = aliases[0];
1749 expect(alias, isNotNull); 1964 expect(alias, isNotNull);
1750 expect(alias.name, aliasName); 1965 expect(alias.name, aliasName);
1751 expect(alias.type, isNotNull); 1966 expect(alias.type, isNotNull);
1752 expect(alias.isSynthetic, isFalse); 1967 expect(alias.isSynthetic, isFalse);
1753 } 1968 }
1754 1969
1755 void test_visitTypeAlias_withFormalParameters() { 1970 void test_visitTypeAlias_withFormalParameters() {
1756 ElementHolder holder = new ElementHolder(); 1971 ElementHolder holder = new ElementHolder();
1757 ElementBuilder builder = new ElementBuilder(holder); 1972 ElementBuilder builder = _makeBuilder(holder);
1758 String aliasName = "F"; 1973 String aliasName = "F";
1759 String firstParameterName = "x"; 1974 String firstParameterName = "x";
1760 String secondParameterName = "y"; 1975 String secondParameterName = "y";
1761 TypeAlias typeAlias = AstFactory.typeAlias( 1976 TypeAlias typeAlias = AstFactory.typeAlias(
1762 null, 1977 null,
1763 aliasName, 1978 aliasName,
1764 AstFactory.typeParameterList(), 1979 AstFactory.typeParameterList(),
1765 AstFactory.formalParameterList([ 1980 AstFactory.formalParameterList([
1766 AstFactory.simpleFormalParameter3(firstParameterName), 1981 AstFactory.simpleFormalParameter3(firstParameterName),
1767 AstFactory.simpleFormalParameter3(secondParameterName) 1982 AstFactory.simpleFormalParameter3(secondParameterName)
(...skipping 10 matching lines...) Expand all
1778 expect(parameters, hasLength(2)); 1993 expect(parameters, hasLength(2));
1779 expect(parameters[0].name, firstParameterName); 1994 expect(parameters[0].name, firstParameterName);
1780 expect(parameters[1].name, secondParameterName); 1995 expect(parameters[1].name, secondParameterName);
1781 List<TypeParameterElement> typeParameters = alias.typeParameters; 1996 List<TypeParameterElement> typeParameters = alias.typeParameters;
1782 expect(typeParameters, isNotNull); 1997 expect(typeParameters, isNotNull);
1783 expect(typeParameters, hasLength(0)); 1998 expect(typeParameters, hasLength(0));
1784 } 1999 }
1785 2000
1786 void test_visitTypeAlias_withTypeParameters() { 2001 void test_visitTypeAlias_withTypeParameters() {
1787 ElementHolder holder = new ElementHolder(); 2002 ElementHolder holder = new ElementHolder();
1788 ElementBuilder builder = new ElementBuilder(holder); 2003 ElementBuilder builder = _makeBuilder(holder);
1789 String aliasName = "F"; 2004 String aliasName = "F";
1790 String firstTypeParameterName = "A"; 2005 String firstTypeParameterName = "A";
1791 String secondTypeParameterName = "B"; 2006 String secondTypeParameterName = "B";
1792 TypeAlias typeAlias = AstFactory.typeAlias( 2007 TypeAlias typeAlias = AstFactory.typeAlias(
1793 null, 2008 null,
1794 aliasName, 2009 aliasName,
1795 AstFactory.typeParameterList( 2010 AstFactory.typeParameterList(
1796 [firstTypeParameterName, secondTypeParameterName]), 2011 [firstTypeParameterName, secondTypeParameterName]),
1797 AstFactory.formalParameterList()); 2012 AstFactory.formalParameterList());
1798 typeAlias.accept(builder); 2013 typeAlias.accept(builder);
1799 List<FunctionTypeAliasElement> aliases = holder.typeAliases; 2014 List<FunctionTypeAliasElement> aliases = holder.typeAliases;
1800 expect(aliases, hasLength(1)); 2015 expect(aliases, hasLength(1));
1801 FunctionTypeAliasElement alias = aliases[0]; 2016 FunctionTypeAliasElement alias = aliases[0];
1802 expect(alias, isNotNull); 2017 expect(alias, isNotNull);
1803 expect(alias.name, aliasName); 2018 expect(alias.name, aliasName);
1804 expect(alias.type, isNotNull); 2019 expect(alias.type, isNotNull);
1805 expect(alias.isSynthetic, isFalse); 2020 expect(alias.isSynthetic, isFalse);
1806 List<VariableElement> parameters = alias.parameters; 2021 List<VariableElement> parameters = alias.parameters;
1807 expect(parameters, isNotNull); 2022 expect(parameters, isNotNull);
1808 expect(parameters, hasLength(0)); 2023 expect(parameters, hasLength(0));
1809 List<TypeParameterElement> typeParameters = alias.typeParameters; 2024 List<TypeParameterElement> typeParameters = alias.typeParameters;
1810 expect(typeParameters, hasLength(2)); 2025 expect(typeParameters, hasLength(2));
1811 expect(typeParameters[0].name, firstTypeParameterName); 2026 expect(typeParameters[0].name, firstTypeParameterName);
1812 expect(typeParameters[1].name, secondTypeParameterName); 2027 expect(typeParameters[1].name, secondTypeParameterName);
1813 } 2028 }
1814 2029
1815 void test_visitTypeParameter() { 2030 void test_visitTypeParameter() {
1816 ElementHolder holder = new ElementHolder(); 2031 ElementHolder holder = new ElementHolder();
1817 ElementBuilder builder = new ElementBuilder(holder); 2032 ElementBuilder builder = _makeBuilder(holder);
1818 String parameterName = "E"; 2033 String parameterName = "E";
1819 TypeParameter typeParameter = AstFactory.typeParameter(parameterName); 2034 TypeParameter typeParameter = AstFactory.typeParameter(parameterName);
1820 typeParameter.accept(builder); 2035 typeParameter.accept(builder);
1821 List<TypeParameterElement> typeParameters = holder.typeParameters; 2036 List<TypeParameterElement> typeParameters = holder.typeParameters;
1822 expect(typeParameters, hasLength(1)); 2037 expect(typeParameters, hasLength(1));
1823 TypeParameterElement typeParameterElement = typeParameters[0]; 2038 TypeParameterElement typeParameterElement = typeParameters[0];
1824 expect(typeParameterElement, isNotNull); 2039 expect(typeParameterElement, isNotNull);
1825 expect(typeParameterElement.name, parameterName); 2040 expect(typeParameterElement.name, parameterName);
1826 expect(typeParameterElement.bound, isNull); 2041 expect(typeParameterElement.bound, isNull);
1827 expect(typeParameterElement.isSynthetic, isFalse); 2042 expect(typeParameterElement.isSynthetic, isFalse);
1828 } 2043 }
1829 2044
1830 void test_visitVariableDeclaration_inConstructor() { 2045 void test_visitVariableDeclaration_inConstructor() {
1831 ElementHolder holder = new ElementHolder(); 2046 ElementHolder holder = new ElementHolder();
1832 ElementBuilder builder = new ElementBuilder(holder); 2047 ElementBuilder builder = _makeBuilder(holder);
1833 // 2048 //
1834 // C() {var v;} 2049 // C() {var v;}
1835 // 2050 //
1836 String variableName = "v"; 2051 String variableName = "v";
1837 VariableDeclaration variable = 2052 VariableDeclaration variable =
1838 AstFactory.variableDeclaration2(variableName, null); 2053 AstFactory.variableDeclaration2(variableName, null);
1839 Statement statement = 2054 Statement statement =
1840 AstFactory.variableDeclarationStatement2(null, [variable]); 2055 AstFactory.variableDeclarationStatement2(null, [variable]);
1841 ConstructorDeclaration constructor = AstFactory.constructorDeclaration2( 2056 ConstructorDeclaration constructor = AstFactory.constructorDeclaration2(
1842 null, 2057 null,
(...skipping 10 matching lines...) Expand all
1853 List<LocalVariableElement> variableElements = 2068 List<LocalVariableElement> variableElements =
1854 constructors[0].localVariables; 2069 constructors[0].localVariables;
1855 expect(variableElements, hasLength(1)); 2070 expect(variableElements, hasLength(1));
1856 LocalVariableElement variableElement = variableElements[0]; 2071 LocalVariableElement variableElement = variableElements[0];
1857 expect(variableElement.hasImplicitType, isTrue); 2072 expect(variableElement.hasImplicitType, isTrue);
1858 expect(variableElement.name, variableName); 2073 expect(variableElement.name, variableName);
1859 } 2074 }
1860 2075
1861 void test_visitVariableDeclaration_inMethod() { 2076 void test_visitVariableDeclaration_inMethod() {
1862 ElementHolder holder = new ElementHolder(); 2077 ElementHolder holder = new ElementHolder();
1863 ElementBuilder builder = new ElementBuilder(holder); 2078 ElementBuilder builder = _makeBuilder(holder);
1864 // 2079 //
1865 // m() {T v;} 2080 // m() {T v;}
1866 // 2081 //
1867 String variableName = "v"; 2082 String variableName = "v";
1868 VariableDeclaration variable = 2083 VariableDeclaration variable =
1869 AstFactory.variableDeclaration2(variableName, null); 2084 AstFactory.variableDeclaration2(variableName, null);
1870 Statement statement = AstFactory.variableDeclarationStatement( 2085 Statement statement = AstFactory.variableDeclarationStatement(
1871 null, AstFactory.typeName4('T'), [variable]); 2086 null, AstFactory.typeName4('T'), [variable]);
1872 MethodDeclaration method = AstFactory.methodDeclaration2( 2087 MethodDeclaration method = AstFactory.methodDeclaration2(
1873 null, 2088 null,
1874 null, 2089 null,
1875 null, 2090 null,
1876 null, 2091 null,
1877 AstFactory.identifier3("m"), 2092 AstFactory.identifier3("m"),
1878 AstFactory.formalParameterList(), 2093 AstFactory.formalParameterList(),
1879 AstFactory.blockFunctionBody2([statement])); 2094 AstFactory.blockFunctionBody2([statement]));
1880 method.accept(builder); 2095 method.accept(builder);
1881 2096
1882 List<MethodElement> methods = holder.methods; 2097 List<MethodElement> methods = holder.methods;
1883 expect(methods, hasLength(1)); 2098 expect(methods, hasLength(1));
1884 List<LocalVariableElement> variableElements = methods[0].localVariables; 2099 List<LocalVariableElement> variableElements = methods[0].localVariables;
1885 expect(variableElements, hasLength(1)); 2100 expect(variableElements, hasLength(1));
1886 LocalVariableElement variableElement = variableElements[0]; 2101 LocalVariableElement variableElement = variableElements[0];
1887 expect(variableElement.hasImplicitType, isFalse); 2102 expect(variableElement.hasImplicitType, isFalse);
1888 expect(variableElement.name, variableName); 2103 expect(variableElement.name, variableName);
1889 } 2104 }
1890 2105
1891 void test_visitVariableDeclaration_localNestedInFunction() { 2106 void test_visitVariableDeclaration_localNestedInFunction() {
1892 ElementHolder holder = new ElementHolder(); 2107 ElementHolder holder = new ElementHolder();
1893 ElementBuilder builder = new ElementBuilder(holder); 2108 ElementBuilder builder = _makeBuilder(holder);
1894 // 2109 //
1895 // var f = () {var v;}; 2110 // var f = () {var v;};
1896 // 2111 //
1897 String variableName = "v"; 2112 String variableName = "v";
1898 VariableDeclaration variable = 2113 VariableDeclaration variable =
1899 AstFactory.variableDeclaration2(variableName, null); 2114 AstFactory.variableDeclaration2(variableName, null);
1900 Statement statement = 2115 Statement statement =
1901 AstFactory.variableDeclarationStatement2(null, [variable]); 2116 AstFactory.variableDeclarationStatement2(null, [variable]);
1902 Expression initializer = AstFactory.functionExpression2( 2117 Expression initializer = AstFactory.functionExpression2(
1903 AstFactory.formalParameterList(), 2118 AstFactory.formalParameterList(),
(...skipping 20 matching lines...) Expand all
1924 expect(variableElement.hasImplicitType, isTrue); 2139 expect(variableElement.hasImplicitType, isTrue);
1925 expect(variableElement.isConst, isFalse); 2140 expect(variableElement.isConst, isFalse);
1926 expect(variableElement.isFinal, isFalse); 2141 expect(variableElement.isFinal, isFalse);
1927 expect(variableElement.isSynthetic, isFalse); 2142 expect(variableElement.isSynthetic, isFalse);
1928 expect(variableElement.name, variableName); 2143 expect(variableElement.name, variableName);
1929 } 2144 }
1930 2145
1931 void test_visitVariableDeclaration_noInitializer() { 2146 void test_visitVariableDeclaration_noInitializer() {
1932 // var v; 2147 // var v;
1933 ElementHolder holder = new ElementHolder(); 2148 ElementHolder holder = new ElementHolder();
1934 ElementBuilder builder = new ElementBuilder(holder); 2149 ElementBuilder builder = _makeBuilder(holder);
1935 String variableName = "v"; 2150 String variableName = "v";
1936 VariableDeclaration variableDeclaration = 2151 VariableDeclaration variableDeclaration =
1937 AstFactory.variableDeclaration2(variableName, null); 2152 AstFactory.variableDeclaration2(variableName, null);
1938 AstFactory.variableDeclarationList2(null, [variableDeclaration]); 2153 AstFactory.variableDeclarationList2(null, [variableDeclaration]);
1939 variableDeclaration.accept(builder); 2154 variableDeclaration.accept(builder);
1940 2155
1941 List<TopLevelVariableElement> variables = holder.topLevelVariables; 2156 List<TopLevelVariableElement> variables = holder.topLevelVariables;
1942 expect(variables, hasLength(1)); 2157 expect(variables, hasLength(1));
1943 TopLevelVariableElement variable = variables[0]; 2158 TopLevelVariableElement variable = variables[0];
1944 expect(variable, isNotNull); 2159 expect(variable, isNotNull);
1945 expect(variable.hasImplicitType, isTrue); 2160 expect(variable.hasImplicitType, isTrue);
1946 expect(variable.initializer, isNull); 2161 expect(variable.initializer, isNull);
1947 expect(variable.name, variableName); 2162 expect(variable.name, variableName);
1948 expect(variable.isConst, isFalse); 2163 expect(variable.isConst, isFalse);
1949 expect(variable.isFinal, isFalse); 2164 expect(variable.isFinal, isFalse);
1950 expect(variable.isSynthetic, isFalse); 2165 expect(variable.isSynthetic, isFalse);
1951 expect(variable.getter, isNotNull); 2166 expect(variable.getter, isNotNull);
1952 expect(variable.setter, isNotNull); 2167 expect(variable.setter, isNotNull);
1953 } 2168 }
1954 2169
1955 void test_visitVariableDeclaration_top_const_hasInitializer() { 2170 void test_visitVariableDeclaration_top_const_hasInitializer() {
1956 // const v = 42; 2171 // const v = 42;
1957 ElementHolder holder = new ElementHolder(); 2172 ElementHolder holder = new ElementHolder();
1958 ElementBuilder builder = new ElementBuilder(holder); 2173 ElementBuilder builder = _makeBuilder(holder);
1959 String variableName = "v"; 2174 String variableName = "v";
1960 VariableDeclaration variableDeclaration = 2175 VariableDeclaration variableDeclaration =
1961 AstFactory.variableDeclaration2(variableName, AstFactory.integer(42)); 2176 AstFactory.variableDeclaration2(variableName, AstFactory.integer(42));
1962 AstFactory.variableDeclarationList2(Keyword.CONST, [variableDeclaration]); 2177 AstFactory.variableDeclarationList2(Keyword.CONST, [variableDeclaration]);
1963 variableDeclaration.accept(builder); 2178 variableDeclaration.accept(builder);
1964 2179
1965 List<TopLevelVariableElement> variables = holder.topLevelVariables; 2180 List<TopLevelVariableElement> variables = holder.topLevelVariables;
1966 expect(variables, hasLength(1)); 2181 expect(variables, hasLength(1));
1967 TopLevelVariableElement variable = variables[0]; 2182 TopLevelVariableElement variable = variables[0];
1968 expect(variable, new isInstanceOf<ConstTopLevelVariableElementImpl>()); 2183 expect(variable, new isInstanceOf<ConstTopLevelVariableElementImpl>());
1969 expect(variable.initializer, isNotNull); 2184 expect(variable.initializer, isNotNull);
1970 expect(variable.name, variableName); 2185 expect(variable.name, variableName);
1971 expect(variable.hasImplicitType, isTrue); 2186 expect(variable.hasImplicitType, isTrue);
1972 expect(variable.isConst, isTrue); 2187 expect(variable.isConst, isTrue);
1973 expect(variable.isFinal, isFalse); 2188 expect(variable.isFinal, isFalse);
1974 expect(variable.isSynthetic, isFalse); 2189 expect(variable.isSynthetic, isFalse);
1975 expect(variable.getter, isNotNull); 2190 expect(variable.getter, isNotNull);
1976 expect(variable.setter, isNull); 2191 expect(variable.setter, isNull);
1977 } 2192 }
1978 2193
1979 void test_visitVariableDeclaration_top_docRange() { 2194 void test_visitVariableDeclaration_top_docRange() {
1980 // final a, b; 2195 // final a, b;
1981 ElementHolder holder = new ElementHolder(); 2196 ElementHolder holder = new ElementHolder();
1982 ElementBuilder builder = new ElementBuilder(holder); 2197 ElementBuilder builder = _makeBuilder(holder);
1983 VariableDeclaration variableDeclaration1 = 2198 VariableDeclaration variableDeclaration1 =
1984 AstFactory.variableDeclaration('a'); 2199 AstFactory.variableDeclaration('a');
1985 VariableDeclaration variableDeclaration2 = 2200 VariableDeclaration variableDeclaration2 =
1986 AstFactory.variableDeclaration('b'); 2201 AstFactory.variableDeclaration('b');
1987 TopLevelVariableDeclaration topLevelVariableDeclaration = AstFactory 2202 TopLevelVariableDeclaration topLevelVariableDeclaration = AstFactory
1988 .topLevelVariableDeclaration( 2203 .topLevelVariableDeclaration(
1989 Keyword.FINAL, null, [variableDeclaration1, variableDeclaration2]); 2204 Keyword.FINAL, null, [variableDeclaration1, variableDeclaration2]);
1990 topLevelVariableDeclaration.documentationComment = AstFactory 2205 topLevelVariableDeclaration.documentationComment = AstFactory
1991 .documentationComment( 2206 .documentationComment(
1992 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); 2207 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []);
1993 2208
1994 topLevelVariableDeclaration.accept(builder); 2209 topLevelVariableDeclaration.accept(builder);
1995 List<TopLevelVariableElement> variables = holder.topLevelVariables; 2210 List<TopLevelVariableElement> variables = holder.topLevelVariables;
1996 expect(variables, hasLength(2)); 2211 expect(variables, hasLength(2));
1997 2212
1998 TopLevelVariableElement variable1 = variables[0]; 2213 TopLevelVariableElement variable1 = variables[0];
1999 expect(variable1, isNotNull); 2214 expect(variable1, isNotNull);
2000 _assertHasDocRange(variable1, 50, 7); 2215 _assertHasDocRange(variable1, 50, 7);
2001 2216
2002 TopLevelVariableElement variable2 = variables[1]; 2217 TopLevelVariableElement variable2 = variables[1];
2003 expect(variable2, isNotNull); 2218 expect(variable2, isNotNull);
2004 _assertHasDocRange(variable2, 50, 7); 2219 _assertHasDocRange(variable2, 50, 7);
2005 } 2220 }
2006 2221
2007 void test_visitVariableDeclaration_top_final() { 2222 void test_visitVariableDeclaration_top_final() {
2008 // final v; 2223 // final v;
2009 ElementHolder holder = new ElementHolder(); 2224 ElementHolder holder = new ElementHolder();
2010 ElementBuilder builder = new ElementBuilder(holder); 2225 ElementBuilder builder = _makeBuilder(holder);
2011 String variableName = "v"; 2226 String variableName = "v";
2012 VariableDeclaration variableDeclaration = 2227 VariableDeclaration variableDeclaration =
2013 AstFactory.variableDeclaration2(variableName, null); 2228 AstFactory.variableDeclaration2(variableName, null);
2014 AstFactory.variableDeclarationList2(Keyword.FINAL, [variableDeclaration]); 2229 AstFactory.variableDeclarationList2(Keyword.FINAL, [variableDeclaration]);
2015 variableDeclaration.accept(builder); 2230 variableDeclaration.accept(builder);
2016 List<TopLevelVariableElement> variables = holder.topLevelVariables; 2231 List<TopLevelVariableElement> variables = holder.topLevelVariables;
2017 expect(variables, hasLength(1)); 2232 expect(variables, hasLength(1));
2018 TopLevelVariableElement variable = variables[0]; 2233 TopLevelVariableElement variable = variables[0];
2019 expect(variable, isNotNull); 2234 expect(variable, isNotNull);
2020 expect(variable.hasImplicitType, isTrue); 2235 expect(variable.hasImplicitType, isTrue);
2021 expect(variable.initializer, isNull); 2236 expect(variable.initializer, isNull);
2022 expect(variable.name, variableName); 2237 expect(variable.name, variableName);
2023 expect(variable.isConst, isFalse); 2238 expect(variable.isConst, isFalse);
2024 expect(variable.isFinal, isTrue); 2239 expect(variable.isFinal, isTrue);
2025 expect(variable.isSynthetic, isFalse); 2240 expect(variable.isSynthetic, isFalse);
2026 expect(variable.getter, isNotNull); 2241 expect(variable.getter, isNotNull);
2027 expect(variable.setter, isNull); 2242 expect(variable.setter, isNull);
2028 } 2243 }
2029 2244
2030 void _assertHasDocRange( 2245 void _assertHasDocRange(
2031 Element element, int expectedOffset, int expectedLength) { 2246 Element element, int expectedOffset, int expectedLength) {
2032 // Cast to dynamic here to avoid a hint about @deprecated docRange. 2247 // Cast to dynamic here to avoid a hint about @deprecated docRange.
2033 SourceRange docRange = (element as dynamic).docRange; 2248 SourceRange docRange = (element as dynamic).docRange;
2034 expect(docRange, isNotNull); 2249 expect(docRange, isNotNull);
2035 expect(docRange.offset, expectedOffset); 2250 expect(docRange.offset, expectedOffset);
2036 expect(docRange.length, expectedLength); 2251 expect(docRange.length, expectedLength);
2037 } 2252 }
2038 2253
2254 ElementBuilder _makeBuilder(ElementHolder holder) =>
2255 new ElementBuilder(holder, new CompilationUnitElementImpl('test.dart'));
2256
2039 void _useParameterInMethod( 2257 void _useParameterInMethod(
2040 FormalParameter formalParameter, int blockOffset, int blockEnd) { 2258 FormalParameter formalParameter, int blockOffset, int blockEnd) {
2041 Block block = AstFactory.block(); 2259 Block block = AstFactory.block();
2042 block.leftBracket.offset = blockOffset; 2260 block.leftBracket.offset = blockOffset;
2043 block.rightBracket.offset = blockEnd - 1; 2261 block.rightBracket.offset = blockEnd - 1;
2044 BlockFunctionBody body = AstFactory.blockFunctionBody(block); 2262 BlockFunctionBody body = AstFactory.blockFunctionBody(block);
2045 AstFactory.methodDeclaration2( 2263 AstFactory.methodDeclaration2(
2046 null, 2264 null,
2047 null, 2265 null,
2048 null, 2266 null,
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
2571 2789
2572 void _assertGetter(FieldElement field) { 2790 void _assertGetter(FieldElement field) {
2573 PropertyAccessorElement getter = field.getter; 2791 PropertyAccessorElement getter = field.getter;
2574 expect(getter, isNotNull); 2792 expect(getter, isNotNull);
2575 expect(getter.variable, same(field)); 2793 expect(getter.variable, same(field));
2576 expect(getter.type, isNotNull); 2794 expect(getter.type, isNotNull);
2577 } 2795 }
2578 2796
2579 ClassElement _buildElement(EnumDeclaration enumDeclaration) { 2797 ClassElement _buildElement(EnumDeclaration enumDeclaration) {
2580 ElementHolder holder = new ElementHolder(); 2798 ElementHolder holder = new ElementHolder();
2581 ElementBuilder elementBuilder = new ElementBuilder(holder); 2799 ElementBuilder elementBuilder = _makeBuilder(holder);
2582 enumDeclaration.accept(elementBuilder); 2800 enumDeclaration.accept(elementBuilder);
2583 EnumMemberBuilder memberBuilder = 2801 EnumMemberBuilder memberBuilder =
2584 new EnumMemberBuilder(new TestTypeProvider()); 2802 new EnumMemberBuilder(new TestTypeProvider());
2585 enumDeclaration.accept(memberBuilder); 2803 enumDeclaration.accept(memberBuilder);
2586 List<ClassElement> enums = holder.enums; 2804 List<ClassElement> enums = holder.enums;
2587 expect(enums, hasLength(1)); 2805 expect(enums, hasLength(1));
2588 return enums[0]; 2806 return enums[0];
2589 } 2807 }
2808
2809 ElementBuilder _makeBuilder(ElementHolder holder) =>
2810 new ElementBuilder(holder, new CompilationUnitElementImpl('test.dart'));
2590 } 2811 }
2591 2812
2592 @reflectiveTest 2813 @reflectiveTest
2593 class ErrorReporterTest extends EngineTestCase { 2814 class ErrorReporterTest extends EngineTestCase {
2594 /** 2815 /**
2595 * Create a type with the given name in a compilation unit with the given name . 2816 * Create a type with the given name in a compilation unit with the given name .
2596 * 2817 *
2597 * @param fileName the name of the compilation unit containing the class 2818 * @param fileName the name of the compilation unit containing the class
2598 * @param typeName the name of the type to be created 2819 * @param typeName the name of the type to be created
2599 * @return the type that was created 2820 * @return the type that was created
(...skipping 1216 matching lines...) Expand 10 before | Expand all | Expand 10 after
3816 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI)); 4037 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI));
3817 expect(UriKind.fromEncoding(0x58), same(null)); 4038 expect(UriKind.fromEncoding(0x58), same(null));
3818 } 4039 }
3819 4040
3820 void test_getEncoding() { 4041 void test_getEncoding() {
3821 expect(UriKind.DART_URI.encoding, 0x64); 4042 expect(UriKind.DART_URI.encoding, 0x64);
3822 expect(UriKind.FILE_URI.encoding, 0x66); 4043 expect(UriKind.FILE_URI.encoding, 0x66);
3823 expect(UriKind.PACKAGE_URI.encoding, 0x70); 4044 expect(UriKind.PACKAGE_URI.encoding, 0x70);
3824 } 4045 }
3825 } 4046 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | pkg/analyzer/test/generated/incremental_resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698