OLD | NEW |
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.src.context.context_test; | 5 library analyzer.test.src.context.context_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 | 9 |
10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
(...skipping 3481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3492 context.setContents(a, newCode); | 3492 context.setContents(a, newCode); |
3493 _performPendingAnalysisTasks(); | 3493 _performPendingAnalysisTasks(); |
3494 // Validate "(p) => 4.2" types. | 3494 // Validate "(p) => 4.2" types. |
3495 CompilationUnit unit = context.getResult(targetA, RESOLVED_UNIT2); | 3495 CompilationUnit unit = context.getResult(targetA, RESOLVED_UNIT2); |
3496 SimpleIdentifier parameterName = | 3496 SimpleIdentifier parameterName = |
3497 EngineTestCase.findSimpleIdentifier(unit, newCode, 'p) => 4.2);'); | 3497 EngineTestCase.findSimpleIdentifier(unit, newCode, 'p) => 4.2);'); |
3498 expect(parameterName.staticType, context.typeProvider.dynamicType); | 3498 expect(parameterName.staticType, context.typeProvider.dynamicType); |
3499 expect(parameterName.propagatedType, context.typeProvider.intType); | 3499 expect(parameterName.propagatedType, context.typeProvider.intType); |
3500 } | 3500 } |
3501 | 3501 |
| 3502 void test_sequence_compoundingResults_exportNamespace() { |
| 3503 Source a = addSource( |
| 3504 '/a.dart', |
| 3505 r''' |
| 3506 class A<T> {} |
| 3507 '''); |
| 3508 Source b = addSource( |
| 3509 '/b.dart', |
| 3510 r''' |
| 3511 export 'a.dart'; |
| 3512 '''); |
| 3513 Source c = addSource( |
| 3514 '/c.dart', |
| 3515 r''' |
| 3516 import 'b.dart'; |
| 3517 main() { |
| 3518 new A<int>(); |
| 3519 } |
| 3520 '''); |
| 3521 _performPendingAnalysisTasks(); |
| 3522 expect(context.getErrors(c).errors, isEmpty); |
| 3523 // Update a.dart, so that `A<T>` has a type bound. |
| 3524 // This should invalidate export namespace for b.dart. |
| 3525 // Currently we invalidate the whole LIBRARY_ELEMENT4. |
| 3526 // So, c.dart will see the new `A<T extends B>` and report an error. |
| 3527 context.setContents( |
| 3528 a, |
| 3529 r''' |
| 3530 class A<T extends B> {} |
| 3531 class B {} |
| 3532 '''); |
| 3533 _assertInvalid(b, LIBRARY_ELEMENT4); |
| 3534 // Analyze and validate that a new error is reported. |
| 3535 _performPendingAnalysisTasks(); |
| 3536 expect(context.getErrors(c).errors, hasLength(1)); |
| 3537 _assertValid(a, LIBRARY_ERRORS_READY); |
| 3538 _assertValid(b, LIBRARY_ERRORS_READY); |
| 3539 _assertValid(c, LIBRARY_ERRORS_READY); |
| 3540 } |
| 3541 |
| 3542 void test_sequence_compoundingResults_invalidateButKeepDependency() { |
| 3543 Source a = addSource( |
| 3544 '/a.dart', |
| 3545 r''' |
| 3546 import 'b.dart'; |
| 3547 class A {} |
| 3548 '''); |
| 3549 Source b = addSource( |
| 3550 '/b.dart', |
| 3551 r''' |
| 3552 import 'a.dart'; |
| 3553 import 'c.dart'; |
| 3554 class B {} |
| 3555 '''); |
| 3556 Source c = addSource( |
| 3557 '/c.dart', |
| 3558 r''' |
| 3559 class C {} |
| 3560 '''); |
| 3561 Source d = addSource( |
| 3562 '/d.dart', |
| 3563 r''' |
| 3564 export 'b.dart'; |
| 3565 '''); |
| 3566 _performPendingAnalysisTasks(); |
| 3567 expect(context.getErrors(c).errors, isEmpty); |
| 3568 // Update: a.dart (limited) and b.dart (limited). |
| 3569 // This should invalidate LIBRARY_ELEMENT4 in d.dart, but it should be |
| 3570 // done in a way that keep dependency of other results od d.dart on |
| 3571 // LIBRARY_ELEMENT4 of d.dart, so that when we perform unlimited |
| 3572 // invalidation of c.dart, this makes d.dart invalid. |
| 3573 context.setContents( |
| 3574 a, |
| 3575 r''' |
| 3576 import 'b.dart'; |
| 3577 class A2 {} |
| 3578 '''); |
| 3579 context.setContents( |
| 3580 b, |
| 3581 r''' |
| 3582 import 'a.dart'; |
| 3583 import 'c.dart'; |
| 3584 class B2 {} |
| 3585 '''); |
| 3586 context.setContents( |
| 3587 c, |
| 3588 r''' |
| 3589 import 'dart:async'; |
| 3590 class C {} |
| 3591 '''); |
| 3592 _assertInvalid(d, LIBRARY_ELEMENT4); |
| 3593 _assertInvalid(d, LIBRARY_ERRORS_READY); |
| 3594 // Analyze and validate that a new error is reported. |
| 3595 _performPendingAnalysisTasks(); |
| 3596 _assertValid(a, EXPORT_SOURCE_CLOSURE); |
| 3597 _assertValid(b, EXPORT_SOURCE_CLOSURE); |
| 3598 _assertValid(c, EXPORT_SOURCE_CLOSURE); |
| 3599 _assertValid(d, EXPORT_SOURCE_CLOSURE); |
| 3600 _assertValid(a, LIBRARY_ERRORS_READY); |
| 3601 _assertValid(b, LIBRARY_ERRORS_READY); |
| 3602 _assertValid(c, LIBRARY_ERRORS_READY); |
| 3603 _assertValid(d, LIBRARY_ERRORS_READY); |
| 3604 } |
| 3605 |
| 3606 void test_sequence_compoundingResults_resolvedTypeNames() { |
| 3607 Source a = addSource( |
| 3608 '/a.dart', |
| 3609 r''' |
| 3610 class A {} |
| 3611 '''); |
| 3612 Source b = addSource( |
| 3613 '/b.dart', |
| 3614 r''' |
| 3615 class B<T> { |
| 3616 B(p); |
| 3617 } |
| 3618 '''); |
| 3619 Source c = addSource( |
| 3620 '/c.dart', |
| 3621 r''' |
| 3622 export 'a.dart'; |
| 3623 export 'b.dart'; |
| 3624 '''); |
| 3625 Source d = addSource( |
| 3626 '/d.dart', |
| 3627 r''' |
| 3628 import 'c.dart'; |
| 3629 main() { |
| 3630 new B<int>(null); |
| 3631 } |
| 3632 '''); |
| 3633 _performPendingAnalysisTasks(); |
| 3634 // Update a.dart and b.dart |
| 3635 // This should invalidate most results in a.dart and b.dart |
| 3636 // |
| 3637 // This should also invalidate "compounding" results in c.dart, such as |
| 3638 // READY_LIBRARY_ELEMENT6, which represent a state of the whole source |
| 3639 // closure, not a result of this single unit or a library. |
| 3640 // |
| 3641 // The reason is that although type names (RESOLVED_UNIT5) b.dart will be |
| 3642 // eventually resolved and set into b.dart elements, it may happen |
| 3643 // after we attempted to re-resolve c.dart, which created Member(s), and |
| 3644 // attempts to use elements without types set. |
| 3645 context.setContents( |
| 3646 a, |
| 3647 r''' |
| 3648 class A2 {} |
| 3649 '''); |
| 3650 context.setContents( |
| 3651 b, |
| 3652 r''' |
| 3653 class B<T> { |
| 3654 B(T p); |
| 3655 } |
| 3656 '''); |
| 3657 _assertValidForChangedLibrary(a); |
| 3658 _assertInvalid(a, LIBRARY_ERRORS_READY); |
| 3659 _assertValidForChangedLibrary(b); |
| 3660 _assertInvalid(b, LIBRARY_ERRORS_READY); |
| 3661 _assertInvalid(c, READY_LIBRARY_ELEMENT6); |
| 3662 _assertInvalid(c, READY_LIBRARY_ELEMENT7); |
| 3663 // Analyze and validate that all results are valid. |
| 3664 _performPendingAnalysisTasks(); |
| 3665 _assertValid(a, LIBRARY_ERRORS_READY); |
| 3666 _assertValid(b, LIBRARY_ERRORS_READY); |
| 3667 _assertValid(c, LIBRARY_ERRORS_READY); |
| 3668 _assertValid(d, LIBRARY_ERRORS_READY); |
| 3669 } |
| 3670 |
3502 void test_sequence_dependenciesWithCycles() { | 3671 void test_sequence_dependenciesWithCycles() { |
3503 Source a = addSource( | 3672 Source a = addSource( |
3504 '/a.dart', | 3673 '/a.dart', |
3505 r''' | 3674 r''' |
3506 const A = 1; | 3675 const A = 1; |
3507 '''); | 3676 '''); |
3508 Source b = addSource( | 3677 Source b = addSource( |
3509 '/b.dart', | 3678 '/b.dart', |
3510 r''' | 3679 r''' |
3511 import 'c.dart'; | 3680 import 'c.dart'; |
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4308 void _assertValidAllErrors(Source unit) { | 4477 void _assertValidAllErrors(Source unit) { |
4309 for (ListResultDescriptor<AnalysisError> result in ERROR_SOURCE_RESULTS) { | 4478 for (ListResultDescriptor<AnalysisError> result in ERROR_SOURCE_RESULTS) { |
4310 _assertValid(unit, result); | 4479 _assertValid(unit, result); |
4311 } | 4480 } |
4312 for (ListResultDescriptor<AnalysisError> result in ERROR_UNIT_RESULTS) { | 4481 for (ListResultDescriptor<AnalysisError> result in ERROR_UNIT_RESULTS) { |
4313 _assertUnitValid(unit, result); | 4482 _assertUnitValid(unit, result); |
4314 } | 4483 } |
4315 } | 4484 } |
4316 | 4485 |
4317 void _assertValidAllLibraryUnitResults(Source source, {Source library}) { | 4486 void _assertValidAllLibraryUnitResults(Source source, {Source library}) { |
| 4487 library ??= source; |
4318 for (ResultDescriptor<LibraryElement> result in LIBRARY_ELEMENT_RESULTS) { | 4488 for (ResultDescriptor<LibraryElement> result in LIBRARY_ELEMENT_RESULTS) { |
4319 _assertValid(source, result); | 4489 if (result == LIBRARY_ELEMENT4) { |
| 4490 continue; |
| 4491 } |
| 4492 _assertValid(library, result); |
4320 } | 4493 } |
4321 library ??= source; | |
4322 LibrarySpecificUnit target = new LibrarySpecificUnit(library, source); | 4494 LibrarySpecificUnit target = new LibrarySpecificUnit(library, source); |
4323 for (ResultDescriptor<CompilationUnit> result in RESOLVED_UNIT_RESULTS) { | 4495 for (ResultDescriptor<CompilationUnit> result in RESOLVED_UNIT_RESULTS) { |
4324 _assertValid(target, result); | 4496 _assertValid(target, result); |
4325 } | 4497 } |
4326 } | 4498 } |
4327 | 4499 |
4328 void _assertValidAllResolution(Source unit) { | 4500 void _assertValidAllResolution(Source unit) { |
4329 _assertValidUnits(unit, null); | 4501 _assertValidUnits(unit, null); |
4330 _assertUnitValidTaskResults(unit, ResolveUnitTypeNamesTask.DESCRIPTOR); | 4502 _assertUnitValidTaskResults(unit, ResolveUnitTypeNamesTask.DESCRIPTOR); |
4331 _assertUnitValidTaskResults(unit, ResolveUnitTask.DESCRIPTOR); | 4503 _assertUnitValidTaskResults(unit, ResolveUnitTask.DESCRIPTOR); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4520 * Initialize the visitor. | 4692 * Initialize the visitor. |
4521 */ | 4693 */ |
4522 _ElementGatherer(); | 4694 _ElementGatherer(); |
4523 | 4695 |
4524 @override | 4696 @override |
4525 void visitElement(Element element) { | 4697 void visitElement(Element element) { |
4526 elements[element] = element; | 4698 elements[element] = element; |
4527 super.visitElement(element); | 4699 super.visitElement(element); |
4528 } | 4700 } |
4529 } | 4701 } |
OLD | NEW |