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

Side by Side Diff: pkg/analyzer/test/src/task/dart_test.dart

Issue 2835703002: Remove ReferencedNames(Builder). (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analyzer/test/generated/incremental_resolver_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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.task.dart_test; 5 library analyzer.test.src.task.dart_test;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart';
9 import 'package:analyzer/dart/ast/token.dart'; 9 import 'package:analyzer/dart/ast/token.dart';
10 import 'package:analyzer/dart/ast/visitor.dart'; 10 import 'package:analyzer/dart/ast/visitor.dart';
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 defineReflectiveTests(GatherUsedLocalElementsTaskTest); 56 defineReflectiveTests(GatherUsedLocalElementsTaskTest);
57 defineReflectiveTests(GenerateHintsTaskTest); 57 defineReflectiveTests(GenerateHintsTaskTest);
58 defineReflectiveTests(GenerateLintsTaskTest); 58 defineReflectiveTests(GenerateLintsTaskTest);
59 defineReflectiveTests(InferInstanceMembersInUnitTaskTest); 59 defineReflectiveTests(InferInstanceMembersInUnitTaskTest);
60 defineReflectiveTests(InferStaticVariableTypesInUnitTaskTest); 60 defineReflectiveTests(InferStaticVariableTypesInUnitTaskTest);
61 defineReflectiveTests(InferStaticVariableTypeTaskTest); 61 defineReflectiveTests(InferStaticVariableTypeTaskTest);
62 defineReflectiveTests(LibraryErrorsReadyTaskTest); 62 defineReflectiveTests(LibraryErrorsReadyTaskTest);
63 defineReflectiveTests(LibraryUnitErrorsTaskTest); 63 defineReflectiveTests(LibraryUnitErrorsTaskTest);
64 defineReflectiveTests(ParseDartTaskTest); 64 defineReflectiveTests(ParseDartTaskTest);
65 defineReflectiveTests(PartiallyResolveUnitReferencesTaskTest); 65 defineReflectiveTests(PartiallyResolveUnitReferencesTaskTest);
66 defineReflectiveTests(ReferencedNamesBuilderTest);
67 defineReflectiveTests(ResolveDirectiveElementsTaskTest); 66 defineReflectiveTests(ResolveDirectiveElementsTaskTest);
68 defineReflectiveTests(ResolveInstanceFieldsInUnitTaskTest); 67 defineReflectiveTests(ResolveInstanceFieldsInUnitTaskTest);
69 defineReflectiveTests(ResolveLibraryTaskTest); 68 defineReflectiveTests(ResolveLibraryTaskTest);
70 defineReflectiveTests(ResolveLibraryTypeNamesTaskTest); 69 defineReflectiveTests(ResolveLibraryTypeNamesTaskTest);
71 defineReflectiveTests(ResolveTopLevelUnitTypeBoundsTaskTest); 70 defineReflectiveTests(ResolveTopLevelUnitTypeBoundsTaskTest);
72 defineReflectiveTests(ResolveUnitTaskTest); 71 defineReflectiveTests(ResolveUnitTaskTest);
73 defineReflectiveTests(ResolveUnitTypeNamesTaskTest); 72 defineReflectiveTests(ResolveUnitTypeNamesTaskTest);
74 defineReflectiveTests(ResolveVariableReferencesTaskTest); 73 defineReflectiveTests(ResolveVariableReferencesTaskTest);
75 defineReflectiveTests(ScanDartTaskTest); 74 defineReflectiveTests(ScanDartTaskTest);
76 defineReflectiveTests(StrongModeInferenceTest); 75 defineReflectiveTests(StrongModeInferenceTest);
(...skipping 3089 matching lines...) Expand 10 before | Expand all | Expand 10 after
3166 } 3165 }
3167 3166
3168 @reflectiveTest 3167 @reflectiveTest
3169 class ParseDartTaskTest extends _AbstractDartTaskTest { 3168 class ParseDartTaskTest extends _AbstractDartTaskTest {
3170 Source source; 3169 Source source;
3171 3170
3172 test_perform() { 3171 test_perform() {
3173 _performParseTask(r''' 3172 _performParseTask(r'''
3174 part of lib; 3173 part of lib;
3175 class B {}'''); 3174 class B {}''');
3176 expect(outputs, hasLength(11)); 3175 expect(outputs, hasLength(10));
3177 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0)); 3176 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0));
3178 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); 3177 expect(outputs[EXPORTED_LIBRARIES], hasLength(0));
3179 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); 3178 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1);
3180 expect(outputs[INCLUDED_PARTS], hasLength(0)); 3179 expect(outputs[INCLUDED_PARTS], hasLength(0));
3181 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(1)); 3180 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(1));
3182 expect(outputs[PARSE_ERRORS], hasLength(0)); 3181 expect(outputs[PARSE_ERRORS], hasLength(0));
3183 expect(outputs[PARSED_UNIT], isNotNull); 3182 expect(outputs[PARSED_UNIT], isNotNull);
3184 expect(outputs[REFERENCED_NAMES], isNotNull);
3185 expect(outputs[REFERENCED_SOURCES], hasLength(2)); 3183 expect(outputs[REFERENCED_SOURCES], hasLength(2));
3186 expect(outputs[SOURCE_KIND], SourceKind.PART); 3184 expect(outputs[SOURCE_KIND], SourceKind.PART);
3187 expect(outputs[UNITS], hasLength(1)); 3185 expect(outputs[UNITS], hasLength(1));
3188 } 3186 }
3189 3187
3190 test_perform_computeSourceKind_noDirectives_hasContainingLibrary() { 3188 test_perform_computeSourceKind_noDirectives_hasContainingLibrary() {
3191 // Parse "lib.dart" to let the context know that "test.dart" is included. 3189 // Parse "lib.dart" to let the context know that "test.dart" is included.
3192 computeResult( 3190 computeResult(
3193 newSource( 3191 newSource(
3194 '/lib.dart', 3192 '/lib.dart',
3195 r''' 3193 r'''
3196 library lib; 3194 library lib;
3197 part 'test.dart'; 3195 part 'test.dart';
3198 '''), 3196 '''),
3199 PARSED_UNIT); 3197 PARSED_UNIT);
3200 // If there are no the "part of" directive, then it is not a part. 3198 // If there are no the "part of" directive, then it is not a part.
3201 _performParseTask(''); 3199 _performParseTask('');
3202 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); 3200 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY);
3203 } 3201 }
3204 3202
3205 test_perform_computeSourceKind_noDirectives_noContainingLibrary() { 3203 test_perform_computeSourceKind_noDirectives_noContainingLibrary() {
3206 _performParseTask(''); 3204 _performParseTask('');
3207 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); 3205 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY);
3208 } 3206 }
3209 3207
3210 test_perform_doesNotExist() { 3208 test_perform_doesNotExist() {
3211 _performParseTask(null); 3209 _performParseTask(null);
3212 expect(outputs, hasLength(11)); 3210 expect(outputs, hasLength(10));
3213 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0)); 3211 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0));
3214 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); 3212 expect(outputs[EXPORTED_LIBRARIES], hasLength(0));
3215 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); 3213 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1);
3216 expect(outputs[INCLUDED_PARTS], hasLength(0)); 3214 expect(outputs[INCLUDED_PARTS], hasLength(0));
3217 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(1)); 3215 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(1));
3218 expect(outputs[PARSE_ERRORS], hasLength(0)); 3216 expect(outputs[PARSE_ERRORS], hasLength(0));
3219 expect(outputs[PARSED_UNIT], isNotNull); 3217 expect(outputs[PARSED_UNIT], isNotNull);
3220 expect(outputs[REFERENCED_NAMES], isNotNull);
3221 expect(outputs[REFERENCED_SOURCES], hasLength(2)); 3218 expect(outputs[REFERENCED_SOURCES], hasLength(2));
3222 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); 3219 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY);
3223 expect(outputs[UNITS], hasLength(1)); 3220 expect(outputs[UNITS], hasLength(1));
3224 } 3221 }
3225 3222
3226 test_perform_flushTokenStream() { 3223 test_perform_flushTokenStream() {
3227 _performParseTask(r''' 3224 _performParseTask(r'''
3228 class Test {} 3225 class Test {}
3229 '''); 3226 ''');
3230 expect(analysisCache.getState(source, TOKEN_STREAM), CacheState.FLUSHED); 3227 expect(analysisCache.getState(source, TOKEN_STREAM), CacheState.FLUSHED);
3231 } 3228 }
3232 3229
3233 test_perform_invalidDirectives() { 3230 test_perform_invalidDirectives() {
3234 _performParseTask(r''' 3231 _performParseTask(r'''
3235 library lib; 3232 library lib;
3236 import '/does/not/exist.dart'; 3233 import '/does/not/exist.dart';
3237 import '://invaliduri.dart'; 3234 import '://invaliduri.dart';
3238 export '${a}lib3.dart'; 3235 export '${a}lib3.dart';
3239 part 'part.dart'; 3236 part 'part.dart';
3240 class A {}'''); 3237 class A {}''');
3241 expect(outputs, hasLength(11)); 3238 expect(outputs, hasLength(10));
3242 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(1)); 3239 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(1));
3243 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); 3240 expect(outputs[EXPORTED_LIBRARIES], hasLength(0));
3244 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2); 3241 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2);
3245 expect(outputs[INCLUDED_PARTS], hasLength(1)); 3242 expect(outputs[INCLUDED_PARTS], hasLength(1));
3246 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(2)); 3243 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(2));
3247 expect(outputs[PARSE_ERRORS], hasLength(2)); 3244 expect(outputs[PARSE_ERRORS], hasLength(2));
3248 expect(outputs[PARSED_UNIT], isNotNull); 3245 expect(outputs[PARSED_UNIT], isNotNull);
3249 expect(outputs[REFERENCED_NAMES], isNotNull);
3250 expect(outputs[REFERENCED_SOURCES], hasLength(4)); 3246 expect(outputs[REFERENCED_SOURCES], hasLength(4));
3251 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); 3247 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY);
3252 expect(outputs[UNITS], hasLength(2)); 3248 expect(outputs[UNITS], hasLength(2));
3253 } 3249 }
3254 3250
3255 test_perform_library() { 3251 test_perform_library() {
3256 _performParseTask(r''' 3252 _performParseTask(r'''
3257 library lib; 3253 library lib;
3258 import 'lib2.dart'; 3254 import 'lib2.dart';
3259 export 'lib3.dart'; 3255 export 'lib3.dart';
3260 part 'part.dart'; 3256 part 'part.dart';
3261 class A {'''); 3257 class A {''');
3262 expect(outputs, hasLength(11)); 3258 expect(outputs, hasLength(10));
3263 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(1)); 3259 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(1));
3264 expect(outputs[EXPORTED_LIBRARIES], hasLength(1)); 3260 expect(outputs[EXPORTED_LIBRARIES], hasLength(1));
3265 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2); 3261 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2);
3266 expect(outputs[INCLUDED_PARTS], hasLength(1)); 3262 expect(outputs[INCLUDED_PARTS], hasLength(1));
3267 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(2)); 3263 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(2));
3268 expect(outputs[PARSE_ERRORS], hasLength(1)); 3264 expect(outputs[PARSE_ERRORS], hasLength(1));
3269 expect(outputs[PARSED_UNIT], isNotNull); 3265 expect(outputs[PARSED_UNIT], isNotNull);
3270 expect(outputs[REFERENCED_NAMES], isNotNull);
3271 expect(outputs[REFERENCED_SOURCES], hasLength(5)); 3266 expect(outputs[REFERENCED_SOURCES], hasLength(5));
3272 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); 3267 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY);
3273 expect(outputs[UNITS], hasLength(2)); 3268 expect(outputs[UNITS], hasLength(2));
3274 } 3269 }
3275 3270
3276 test_perform_library_configurations_bool1() { 3271 test_perform_library_configurations_bool1() {
3277 context.declaredVariables.define('dart.library.io', 'true'); 3272 context.declaredVariables.define('dart.library.io', 'true');
3278 newSource('/foo.dart', ''); 3273 newSource('/foo.dart', '');
3279 newSource('/foo_io.dart', ''); 3274 newSource('/foo_io.dart', '');
3280 newSource('/foo_html.dart', ''); 3275 newSource('/foo_html.dart', '');
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
3390 library lib; 3385 library lib;
3391 part 'test.dart'; 3386 part 'test.dart';
3392 '''); 3387 ''');
3393 expect(outputs[INCLUDED_PARTS], unorderedEquals(<Source>[source])); 3388 expect(outputs[INCLUDED_PARTS], unorderedEquals(<Source>[source]));
3394 } 3389 }
3395 3390
3396 test_perform_part() { 3391 test_perform_part() {
3397 _performParseTask(r''' 3392 _performParseTask(r'''
3398 part of lib; 3393 part of lib;
3399 class B {}'''); 3394 class B {}''');
3400 expect(outputs, hasLength(11)); 3395 expect(outputs, hasLength(10));
3401 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0)); 3396 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0));
3402 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); 3397 expect(outputs[EXPORTED_LIBRARIES], hasLength(0));
3403 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); 3398 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1);
3404 expect(outputs[INCLUDED_PARTS], hasLength(0)); 3399 expect(outputs[INCLUDED_PARTS], hasLength(0));
3405 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(1)); 3400 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(1));
3406 expect(outputs[PARSE_ERRORS], hasLength(0)); 3401 expect(outputs[PARSE_ERRORS], hasLength(0));
3407 expect(outputs[PARSED_UNIT], isNotNull); 3402 expect(outputs[PARSED_UNIT], isNotNull);
3408 expect(outputs[REFERENCED_NAMES], isNotNull);
3409 expect(outputs[REFERENCED_SOURCES], hasLength(2)); 3403 expect(outputs[REFERENCED_SOURCES], hasLength(2));
3410 expect(outputs[SOURCE_KIND], SourceKind.PART); 3404 expect(outputs[SOURCE_KIND], SourceKind.PART);
3411 expect(outputs[UNITS], hasLength(1)); 3405 expect(outputs[UNITS], hasLength(1));
3412 } 3406 }
3413 3407
3414 /** 3408 /**
3415 * Assert that [sources] contains either just a source with the given 3409 * Assert that [sources] contains either just a source with the given
3416 * [expectedShortName], or it and the `dart:core` source. 3410 * [expectedShortName], or it and the `dart:core` source.
3417 */ 3411 */
3418 void _assertContainsOnlyShortName( 3412 void _assertContainsOnlyShortName(
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
3582 3576
3583 ConstructorDeclaration constructor = members[0]; 3577 ConstructorDeclaration constructor = members[0];
3584 expectReference(constructor.body, false); 3578 expectReference(constructor.body, false);
3585 3579
3586 MethodDeclaration method = members[1]; 3580 MethodDeclaration method = members[1];
3587 expectReference(method.body, false); 3581 expectReference(method.body, false);
3588 } 3582 }
3589 } 3583 }
3590 3584
3591 @reflectiveTest 3585 @reflectiveTest
3592 class ReferencedNamesBuilderTest extends _AbstractDartTaskTest {
3593 void setUp() {
3594 super.setUp();
3595 context.analysisOptions = new AnalysisOptionsImpl()..strongMode = true;
3596 }
3597
3598 test_class_constructor() {
3599 ReferencedNames info = _computeReferencedNames('''
3600 class U {
3601 U.named(A a, B b) {
3602 C c = null;
3603 }
3604 }
3605 ''');
3606 expect(info.names, unorderedEquals(['A', 'B', 'C']));
3607 expect(info.superToSubs.keys, isEmpty);
3608 expect(info.instantiatedNames, isEmpty);
3609 expect(info.userToDependsOn.keys, unorderedEquals(['U']));
3610 expect(info.userToDependsOn['U'], unorderedEquals(['A', 'B']));
3611 }
3612
3613 test_class_extendedUsedUnnamedConstructorNames() {
3614 ReferencedNames info = _computeReferencedNames('''
3615 class U1 extends A {
3616 U1() : super();
3617 }
3618 class U2 extends p.B {
3619 U2() : super();
3620 }
3621 class U3 extends p.C {
3622 U3() : super.named();
3623 }
3624 ''');
3625 expect(
3626 info.extendedUsedUnnamedConstructorNames, unorderedEquals(['A', 'B']));
3627 }
3628
3629 test_class_field() {
3630 ReferencedNames info = _computeReferencedNames('''
3631 class U {
3632 A f = new B();
3633 }
3634 ''');
3635 expect(info.names, unorderedEquals(['A', 'B']));
3636 expect(info.superToSubs.keys, isEmpty);
3637 expect(info.instantiatedNames, unorderedEquals(['B']));
3638 expect(info.userToDependsOn.keys, unorderedEquals(['U']));
3639 expect(info.userToDependsOn['U'], unorderedEquals(['A', 'B']));
3640 }
3641
3642 test_class_getter() {
3643 ReferencedNames info = _computeReferencedNames('''
3644 class U {
3645 A get a => new B();
3646 }
3647 ''');
3648 expect(info.names, unorderedEquals(['A', 'B']));
3649 expect(info.superToSubs.keys, isEmpty);
3650 expect(info.instantiatedNames, unorderedEquals(['B']));
3651 expect(info.userToDependsOn.keys, unorderedEquals(['U']));
3652 expect(info.userToDependsOn['U'], unorderedEquals(['A']));
3653 }
3654
3655 test_class_members() {
3656 ReferencedNames info = _computeReferencedNames('''
3657 class U {
3658 int a;
3659 int get b;
3660 set c(_) {}
3661 m(D d) {
3662 a;
3663 b;
3664 c = 1;
3665 m();
3666 }
3667 }
3668 ''');
3669 expect(info.names, unorderedEquals(['int', 'D']));
3670 expect(info.superToSubs.keys, isEmpty);
3671 expect(info.instantiatedNames, isEmpty);
3672 expect(info.userToDependsOn.keys, unorderedEquals(['U']));
3673 expect(info.userToDependsOn['U'], unorderedEquals(['int', 'D']));
3674 }
3675
3676 test_class_members_dontHideQualified() {
3677 ReferencedNames info = _computeReferencedNames('''
3678 class U {
3679 int a;
3680 int get b;
3681 set c(_) {}
3682 m(D d) {
3683 d.a;
3684 d.b;
3685 d.c;
3686 }
3687 }
3688 ''');
3689 expect(info.names, unorderedEquals(['int', 'D', 'a', 'b', 'c']));
3690 expect(info.superToSubs.keys, isEmpty);
3691 expect(info.instantiatedNames, isEmpty);
3692 expect(info.userToDependsOn.keys, unorderedEquals(['U']));
3693 expect(info.userToDependsOn['U'], unorderedEquals(['int', 'D']));
3694 }
3695
3696 test_class_method() {
3697 ReferencedNames info = _computeReferencedNames('''
3698 class U {
3699 A m(B p) {
3700 C v = 0;
3701 }
3702 }
3703 ''');
3704 expect(info.names, unorderedEquals(['A', 'B', 'C']));
3705 expect(info.superToSubs.keys, isEmpty);
3706 expect(info.instantiatedNames, isEmpty);
3707 expect(info.userToDependsOn.keys, unorderedEquals(['U']));
3708 expect(info.userToDependsOn['U'], unorderedEquals(['A', 'B']));
3709 }
3710
3711 test_class_method_localVariables() {
3712 ReferencedNames info = _computeReferencedNames('''
3713 class U {
3714 A m() {
3715 B b = null;
3716 b;
3717 {
3718 C c = null;
3719 b;
3720 c;
3721 }
3722 d;
3723 }
3724 }
3725 ''');
3726 expect(info.names, unorderedEquals(['A', 'B', 'C', 'd']));
3727 expect(info.superToSubs.keys, isEmpty);
3728 expect(info.instantiatedNames, isEmpty);
3729 expect(info.userToDependsOn.keys, unorderedEquals(['U']));
3730 expect(info.userToDependsOn['U'], unorderedEquals(['A']));
3731 }
3732
3733 test_class_method_parameters() {
3734 ReferencedNames info = _computeReferencedNames('''
3735 class U {
3736 m(A a) {
3737 a;
3738 b;
3739 }
3740 }
3741 ''');
3742 expect(info.names, unorderedEquals(['A', 'b']));
3743 expect(info.superToSubs.keys, isEmpty);
3744 expect(info.instantiatedNames, isEmpty);
3745 expect(info.userToDependsOn.keys, unorderedEquals(['U']));
3746 expect(info.userToDependsOn['U'], unorderedEquals(['A']));
3747 }
3748
3749 test_class_method_typeParameters() {
3750 ReferencedNames info = _computeReferencedNames('''
3751 class U {
3752 A m<T>(B b, T t) {
3753 C c = 0;
3754 }
3755 }
3756 ''');
3757 expect(info.names, unorderedEquals(['A', 'B', 'C']));
3758 expect(info.superToSubs.keys, isEmpty);
3759 expect(info.instantiatedNames, isEmpty);
3760 expect(info.userToDependsOn.keys, unorderedEquals(['U']));
3761 expect(info.userToDependsOn['U'], unorderedEquals(['A', 'B']));
3762 }
3763
3764 test_class_setter() {
3765 ReferencedNames info = _computeReferencedNames('''
3766 class U {
3767 set a(A a) {
3768 B b = null;
3769 }
3770 }
3771 ''');
3772 expect(info.names, unorderedEquals(['A', 'B']));
3773 expect(info.superToSubs.keys, isEmpty);
3774 expect(info.instantiatedNames, isEmpty);
3775 expect(info.userToDependsOn.keys, unorderedEquals(['U']));
3776 expect(info.userToDependsOn['U'], unorderedEquals(['A']));
3777 }
3778
3779 test_class_typeParameters() {
3780 ReferencedNames info = _computeReferencedNames('''
3781 class U<T> {
3782 T f = new A<T>();
3783 }
3784 ''');
3785 expect(info.names, unorderedEquals(['A']));
3786 expect(info.superToSubs.keys, isEmpty);
3787 expect(info.instantiatedNames, unorderedEquals(['A']));
3788 expect(info.userToDependsOn.keys, unorderedEquals(['U']));
3789 expect(info.userToDependsOn['U'], unorderedEquals(['A']));
3790 }
3791
3792 test_instantiatedNames_importPrefix() {
3793 ReferencedNames info = _computeReferencedNames('''
3794 import 'a.dart' as p1;
3795 import 'b.dart' as p2;
3796 main() {
3797 new p1.A();
3798 new p1.A.c1();
3799 new p1.B();
3800 new p2.C();
3801 new D();
3802 new D.c2();
3803 }
3804 ''');
3805 expect(info.names, unorderedEquals(['A', 'B', 'C', 'D', 'c1', 'c2']));
3806 expect(info.superToSubs.keys, isEmpty);
3807 expect(info.instantiatedNames, unorderedEquals(['A', 'B', 'C', 'D']));
3808 expect(info.userToDependsOn.keys, unorderedEquals(['main']));
3809 expect(info.userToDependsOn['main'], isEmpty);
3810 }
3811
3812 test_localFunction() {
3813 ReferencedNames info = _computeReferencedNames('''
3814 f(A a) {
3815 g(B b) {}
3816 }
3817 ''');
3818 expect(info.names, unorderedEquals(['A', 'B']));
3819 expect(info.superToSubs.keys, isEmpty);
3820 expect(info.instantiatedNames, isEmpty);
3821 expect(info.userToDependsOn.keys, unorderedEquals(['f']));
3822 expect(info.userToDependsOn['f'], unorderedEquals(['A']));
3823 }
3824
3825 test_superToSubs_importPrefix() {
3826 ReferencedNames info = _computeReferencedNames('''
3827 import 'a.dart' as p1;
3828 import 'b.dart' as p2;
3829 class U extends p1.A with p2.B implements p2.C {}
3830 ''');
3831 expect(info.names, unorderedEquals(['A', 'B', 'C']));
3832 expect(info.superToSubs.keys, unorderedEquals(['A', 'B', 'C']));
3833 expect(info.superToSubs['A'], unorderedEquals(['U']));
3834 expect(info.superToSubs['B'], unorderedEquals(['U']));
3835 expect(info.superToSubs['C'], unorderedEquals(['U']));
3836 expect(info.instantiatedNames, isEmpty);
3837 expect(info.userToDependsOn.keys, unorderedEquals(['U']));
3838 expect(info.userToDependsOn['U'], unorderedEquals(['A', 'B', 'C']));
3839 }
3840
3841 test_topLevelVariable() {
3842 ReferencedNames info = _computeReferencedNames('''
3843 A v = new B(c);
3844 ''');
3845 expect(info.names, unorderedEquals(['A', 'B', 'c']));
3846 expect(info.superToSubs.keys, isEmpty);
3847 expect(info.instantiatedNames, unorderedEquals(['B']));
3848 expect(info.userToDependsOn.keys, unorderedEquals(['v']));
3849 expect(info.userToDependsOn['v'], unorderedEquals(['A', 'B', 'c']));
3850 }
3851
3852 test_topLevelVariable_multiple() {
3853 ReferencedNames info = _computeReferencedNames('''
3854 A v1 = new B(c), v2 = new D<E>(f);
3855 ''');
3856 expect(info.names, unorderedEquals(['A', 'B', 'c', 'D', 'E', 'f']));
3857 expect(info.superToSubs.keys, isEmpty);
3858 expect(info.instantiatedNames, unorderedEquals(['B', 'D']));
3859 expect(info.userToDependsOn.keys, unorderedEquals(['v1', 'v2']));
3860 expect(info.userToDependsOn['v1'], unorderedEquals(['A', 'B', 'c']));
3861 expect(info.userToDependsOn['v2'], unorderedEquals(['A', 'D', 'E', 'f']));
3862 }
3863
3864 test_unit_classTypeAlias() {
3865 ReferencedNames info = _computeReferencedNames('''
3866 class U = A with B implements C;
3867 ''');
3868 expect(info.names, unorderedEquals(['A', 'B', 'C']));
3869 expect(info.superToSubs.keys, unorderedEquals(['A', 'B', 'C']));
3870 expect(info.superToSubs['A'], unorderedEquals(['U']));
3871 expect(info.superToSubs['B'], unorderedEquals(['U']));
3872 expect(info.superToSubs['C'], unorderedEquals(['U']));
3873 expect(info.instantiatedNames, isEmpty);
3874 expect(info.userToDependsOn.keys, unorderedEquals(['U']));
3875 expect(info.userToDependsOn['U'], unorderedEquals(['A', 'B', 'C']));
3876 }
3877
3878 test_unit_classTypeAlias_typeParameters() {
3879 ReferencedNames info = _computeReferencedNames('''
3880 class U<T1, T2 extends D> = A<T1> with B<T2> implements C<T1, T2>;
3881 ''');
3882 expect(info.names, unorderedEquals(['A', 'B', 'C', 'D']));
3883 expect(info.superToSubs.keys, unorderedEquals(['A', 'B', 'C']));
3884 expect(info.superToSubs['A'], unorderedEquals(['U']));
3885 expect(info.superToSubs['B'], unorderedEquals(['U']));
3886 expect(info.superToSubs['C'], unorderedEquals(['U']));
3887 expect(info.instantiatedNames, isEmpty);
3888 expect(info.userToDependsOn.keys, unorderedEquals(['U']));
3889 expect(info.userToDependsOn['U'], unorderedEquals(['A', 'B', 'C', 'D']));
3890 }
3891
3892 test_unit_function() {
3893 ReferencedNames info = _computeReferencedNames('''
3894 A f(B b) {
3895 C c = 0;
3896 }
3897 ''');
3898 expect(info.names, unorderedEquals(['A', 'B', 'C']));
3899 expect(info.superToSubs.keys, isEmpty);
3900 expect(info.instantiatedNames, isEmpty);
3901 expect(info.userToDependsOn.keys, unorderedEquals(['f']));
3902 expect(info.userToDependsOn['f'], unorderedEquals(['A', 'B']));
3903 }
3904
3905 test_unit_function_doc() {
3906 ReferencedNames info = _computeReferencedNames('''
3907 /**
3908 * Documentation [C.d] reference.
3909 */
3910 A f(B b) {}
3911 ''');
3912 expect(info.names, unorderedEquals(['A', 'B', 'C', 'd']));
3913 expect(info.superToSubs.keys, isEmpty);
3914 expect(info.instantiatedNames, isEmpty);
3915 expect(info.userToDependsOn.keys, unorderedEquals(['f']));
3916 expect(info.userToDependsOn['f'], unorderedEquals(['A', 'B']));
3917 }
3918
3919 test_unit_function_localFunctions() {
3920 ReferencedNames info = _computeReferencedNames('''
3921 A f() {
3922 B b = null;
3923 C g() {}
3924 g();
3925 }
3926 ''');
3927 expect(info.names, unorderedEquals(['A', 'B', 'C']));
3928 expect(info.superToSubs.keys, isEmpty);
3929 expect(info.instantiatedNames, isEmpty);
3930 expect(info.userToDependsOn.keys, unorderedEquals(['f']));
3931 expect(info.userToDependsOn['f'], unorderedEquals(['A']));
3932 }
3933
3934 test_unit_function_localsDontHideQualified() {
3935 ReferencedNames info = _computeReferencedNames('''
3936 f(A a, B b) {
3937 var v = 0;
3938 a.v;
3939 a.b;
3940 }
3941 ''');
3942 expect(info.names, unorderedEquals(['A', 'B', 'v', 'b']));
3943 expect(info.superToSubs.keys, isEmpty);
3944 expect(info.instantiatedNames, isEmpty);
3945 expect(info.userToDependsOn.keys, unorderedEquals(['f']));
3946 expect(info.userToDependsOn['f'], unorderedEquals(['A', 'B']));
3947 }
3948
3949 test_unit_function_localVariables() {
3950 ReferencedNames info = _computeReferencedNames('''
3951 A f() {
3952 B b = null;
3953 b;
3954 {
3955 C c = null;
3956 b;
3957 c;
3958 }
3959 d;
3960 }
3961 ''');
3962 expect(info.names, unorderedEquals(['A', 'B', 'C', 'd']));
3963 expect(info.superToSubs.keys, isEmpty);
3964 expect(info.instantiatedNames, isEmpty);
3965 expect(info.userToDependsOn.keys, unorderedEquals(['f']));
3966 expect(info.userToDependsOn['f'], unorderedEquals(['A']));
3967 }
3968
3969 test_unit_function_parameters() {
3970 ReferencedNames info = _computeReferencedNames('''
3971 A f(B b) {
3972 C c = 0;
3973 b;
3974 }
3975 ''');
3976 expect(info.names, unorderedEquals(['A', 'B', 'C']));
3977 expect(info.superToSubs.keys, isEmpty);
3978 expect(info.instantiatedNames, isEmpty);
3979 expect(info.userToDependsOn.keys, unorderedEquals(['f']));
3980 expect(info.userToDependsOn['f'], unorderedEquals(['A', 'B']));
3981 }
3982
3983 test_unit_function_typeParameters() {
3984 ReferencedNames info = _computeReferencedNames('''
3985 A f<T>(B b, T t) {
3986 C c = 0;
3987 }
3988 ''');
3989 expect(info.names, unorderedEquals(['A', 'B', 'C']));
3990 expect(info.superToSubs.keys, isEmpty);
3991 expect(info.instantiatedNames, isEmpty);
3992 expect(info.userToDependsOn.keys, unorderedEquals(['f']));
3993 expect(info.userToDependsOn['f'], unorderedEquals(['A', 'B']));
3994 }
3995
3996 test_unit_functionTypeAlias() {
3997 ReferencedNames info = _computeReferencedNames('''
3998 typedef A F(B B, C c(D d));
3999 ''');
4000 expect(info.names, unorderedEquals(['A', 'B', 'C', 'D']));
4001 expect(info.superToSubs.keys, isEmpty);
4002 expect(info.instantiatedNames, isEmpty);
4003 expect(info.userToDependsOn.keys, unorderedEquals(['F']));
4004 expect(info.userToDependsOn['F'], unorderedEquals(['A', 'B', 'C', 'D']));
4005 }
4006
4007 test_unit_functionTypeAlias_typeParameters() {
4008 ReferencedNames info = _computeReferencedNames('''
4009 typedef A F<T>(B b, T t);
4010 ''');
4011 expect(info.names, unorderedEquals(['A', 'B']));
4012 expect(info.superToSubs.keys, isEmpty);
4013 expect(info.instantiatedNames, isEmpty);
4014 expect(info.userToDependsOn.keys, unorderedEquals(['F']));
4015 expect(info.userToDependsOn['F'], unorderedEquals(['A', 'B']));
4016 }
4017
4018 test_unit_getter() {
4019 ReferencedNames info = _computeReferencedNames('''
4020 A get aaa {
4021 return new B();
4022 }
4023 ''');
4024 expect(info.names, unorderedEquals(['A', 'B']));
4025 expect(info.superToSubs.keys, isEmpty);
4026 expect(info.instantiatedNames, unorderedEquals(['B']));
4027 expect(info.userToDependsOn.keys, unorderedEquals(['aaa']));
4028 expect(info.userToDependsOn['aaa'], unorderedEquals(['A']));
4029 }
4030
4031 test_unit_setter() {
4032 ReferencedNames info = _computeReferencedNames('''
4033 set aaa(A a) {
4034 B b = null;
4035 }
4036 ''');
4037 expect(info.names, unorderedEquals(['A', 'B']));
4038 expect(info.superToSubs.keys, isEmpty);
4039 expect(info.instantiatedNames, isEmpty);
4040 expect(info.userToDependsOn.keys, unorderedEquals(['aaa']));
4041 expect(info.userToDependsOn['aaa'], unorderedEquals(['A']));
4042 }
4043
4044 ReferencedNames _computeReferencedNames(String code) {
4045 Source source = newSource('/test.dart', code);
4046 computeResult(source, REFERENCED_NAMES, matcher: isParseDartTask);
4047 return outputs[REFERENCED_NAMES];
4048 }
4049 }
4050
4051 @reflectiveTest
4052 class ResolveDirectiveElementsTaskTest extends _AbstractDartTaskTest { 3586 class ResolveDirectiveElementsTaskTest extends _AbstractDartTaskTest {
4053 test_perform() { 3587 test_perform() {
4054 List<Source> sources = newSources({ 3588 List<Source> sources = newSources({
4055 '/libA.dart': ''' 3589 '/libA.dart': '''
4056 library libA; 3590 library libA;
4057 import 'libB.dart'; 3591 import 'libB.dart';
4058 export 'libC.dart'; 3592 export 'libC.dart';
4059 ''', 3593 ''',
4060 '/libB.dart': ''' 3594 '/libB.dart': '''
4061 library libB; 3595 library libB;
(...skipping 1679 matching lines...) Expand 10 before | Expand all | Expand 10 after
5741 /** 5275 /**
5742 * Fill [errorListener] with [result] errors in the current [task]. 5276 * Fill [errorListener] with [result] errors in the current [task].
5743 */ 5277 */
5744 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { 5278 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) {
5745 List<AnalysisError> errors = task.outputs[result] as List<AnalysisError>; 5279 List<AnalysisError> errors = task.outputs[result] as List<AnalysisError>;
5746 expect(errors, isNotNull, reason: result.name); 5280 expect(errors, isNotNull, reason: result.name);
5747 errorListener = new GatheringErrorListener(); 5281 errorListener = new GatheringErrorListener();
5748 errorListener.addAll(errors); 5282 errorListener.addAll(errors);
5749 } 5283 }
5750 } 5284 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/incremental_resolver_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698