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

Side by Side Diff: pkg/analyzer/test/src/dart/analysis/index_test.dart

Issue 2975253002: Format analyzer, analysis_server, analyzer_plugin, front_end and kernel with the latest dartfmt. (Closed)
Patch Set: Created 3 years, 5 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:convert'; 6 import 'dart:convert';
7 7
8 import 'package:analyzer/dart/ast/ast.dart'; 8 import 'package:analyzer/dart/ast/ast.dart';
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/src/dart/analysis/driver.dart'; 10 import 'package:analyzer/src/dart/analysis/driver.dart';
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 class A {} // 1 106 class A {} // 1
107 class B extends A {} // 2 107 class B extends A {} // 2
108 '''); 108 ''');
109 ClassElement elementA = findElement('A'); 109 ClassElement elementA = findElement('A');
110 assertThat(elementA) 110 assertThat(elementA)
111 ..isExtendedAt('A {} // 2', false) 111 ..isExtendedAt('A {} // 2', false)
112 ..isReferencedAt('A {} // 2', false); 112 ..isReferencedAt('A {} // 2', false);
113 } 113 }
114 114
115 test_isExtendedBy_ClassDeclaration_isQualified() async { 115 test_isExtendedBy_ClassDeclaration_isQualified() async {
116 provider.newFile( 116 provider.newFile(_p('$testProject/lib.dart'), '''
117 _p('$testProject/lib.dart'),
118 '''
119 class A {} 117 class A {}
120 '''); 118 ''');
121 await _indexTestUnit(''' 119 await _indexTestUnit('''
122 import 'lib.dart' as p; 120 import 'lib.dart' as p;
123 class B extends p.A {} // 2 121 class B extends p.A {} // 2
124 '''); 122 ''');
125 ClassElement elementA = importedUnit().getType('A'); 123 ClassElement elementA = importedUnit().getType('A');
126 assertThat(elementA).isExtendedAt('A {} // 2', true); 124 assertThat(elementA).isExtendedAt('A {} // 2', true);
127 } 125 }
128 126
(...skipping 12 matching lines...) Expand all
141 class B {} 139 class B {}
142 class C = A with B; 140 class C = A with B;
143 '''); 141 ''');
144 ClassElement elementA = findElement('A'); 142 ClassElement elementA = findElement('A');
145 assertThat(elementA) 143 assertThat(elementA)
146 ..isExtendedAt('A with', false) 144 ..isExtendedAt('A with', false)
147 ..isReferencedAt('A with', false); 145 ..isReferencedAt('A with', false);
148 } 146 }
149 147
150 test_isExtendedBy_ClassTypeAlias_isQualified() async { 148 test_isExtendedBy_ClassTypeAlias_isQualified() async {
151 provider.newFile( 149 provider.newFile(_p('$testProject/lib.dart'), '''
152 _p('$testProject/lib.dart'),
153 '''
154 class A {} 150 class A {}
155 '''); 151 ''');
156 await _indexTestUnit(''' 152 await _indexTestUnit('''
157 import 'lib.dart' as p; 153 import 'lib.dart' as p;
158 class B {} 154 class B {}
159 class C = p.A with B; 155 class C = p.A with B;
160 '''); 156 ''');
161 ClassElement elementA = importedUnit().getType('A'); 157 ClassElement elementA = importedUnit().getType('A');
162 assertThat(elementA) 158 assertThat(elementA)
163 ..isExtendedAt('A with', true) 159 ..isExtendedAt('A with', true)
164 ..isReferencedAt('A with', true); 160 ..isReferencedAt('A with', true);
165 } 161 }
166 162
167 test_isImplementedBy_ClassDeclaration() async { 163 test_isImplementedBy_ClassDeclaration() async {
168 await _indexTestUnit(''' 164 await _indexTestUnit('''
169 class A {} // 1 165 class A {} // 1
170 class B implements A {} // 2 166 class B implements A {} // 2
171 '''); 167 ''');
172 ClassElement elementA = findElement('A'); 168 ClassElement elementA = findElement('A');
173 assertThat(elementA) 169 assertThat(elementA)
174 ..isImplementedAt('A {} // 2', false) 170 ..isImplementedAt('A {} // 2', false)
175 ..isReferencedAt('A {} // 2', false); 171 ..isReferencedAt('A {} // 2', false);
176 } 172 }
177 173
178 test_isImplementedBy_ClassDeclaration_isQualified() async { 174 test_isImplementedBy_ClassDeclaration_isQualified() async {
179 provider.newFile( 175 provider.newFile(_p('$testProject/lib.dart'), '''
180 _p('$testProject/lib.dart'),
181 '''
182 class A {} 176 class A {}
183 '''); 177 ''');
184 await _indexTestUnit(''' 178 await _indexTestUnit('''
185 import 'lib.dart' as p; 179 import 'lib.dart' as p;
186 class B implements p.A {} // 2 180 class B implements p.A {} // 2
187 '''); 181 ''');
188 ClassElement elementA = importedUnit().getType('A'); 182 ClassElement elementA = importedUnit().getType('A');
189 assertThat(elementA) 183 assertThat(elementA)
190 ..isImplementedAt('A {} // 2', true) 184 ..isImplementedAt('A {} // 2', true)
191 ..isReferencedAt('A {} // 2', true); 185 ..isReferencedAt('A {} // 2', true);
(...skipping 20 matching lines...) Expand all
212 field(); // nq 206 field(); // nq
213 } 207 }
214 }'''); 208 }''');
215 FieldElement field = findElement('field'); 209 FieldElement field = findElement('field');
216 assertThat(field.getter) 210 assertThat(field.getter)
217 ..isInvokedAt('field(); // q', true) 211 ..isInvokedAt('field(); // q', true)
218 ..isInvokedAt('field(); // nq', false); 212 ..isInvokedAt('field(); // nq', false);
219 } 213 }
220 214
221 test_isInvokedBy_FunctionElement() async { 215 test_isInvokedBy_FunctionElement() async {
222 provider.newFile( 216 provider.newFile(_p('$testProject/lib.dart'), '''
223 _p('$testProject/lib.dart'),
224 '''
225 library lib; 217 library lib;
226 foo() {} 218 foo() {}
227 '''); 219 ''');
228 await _indexTestUnit(''' 220 await _indexTestUnit('''
229 import 'lib.dart'; 221 import 'lib.dart';
230 import 'lib.dart' as pref; 222 import 'lib.dart' as pref;
231 main() { 223 main() {
232 pref.foo(); // q 224 pref.foo(); // q
233 foo(); // nq 225 foo(); // nq
234 }'''); 226 }''');
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 class A {} // 1 343 class A {} // 1
352 class B extends Object with A {} // 2 344 class B extends Object with A {} // 2
353 '''); 345 ''');
354 ClassElement elementA = findElement('A'); 346 ClassElement elementA = findElement('A');
355 assertThat(elementA) 347 assertThat(elementA)
356 ..isMixedInAt('A {} // 2', false) 348 ..isMixedInAt('A {} // 2', false)
357 ..isReferencedAt('A {} // 2', false); 349 ..isReferencedAt('A {} // 2', false);
358 } 350 }
359 351
360 test_isMixedInBy_ClassDeclaration_isQualified() async { 352 test_isMixedInBy_ClassDeclaration_isQualified() async {
361 provider.newFile( 353 provider.newFile(_p('$testProject/lib.dart'), '''
362 _p('$testProject/lib.dart'),
363 '''
364 class A {} 354 class A {}
365 '''); 355 ''');
366 await _indexTestUnit(''' 356 await _indexTestUnit('''
367 import 'lib.dart' as p; 357 import 'lib.dart' as p;
368 class B extends Object with p.A {} // 2 358 class B extends Object with p.A {} // 2
369 '''); 359 ''');
370 ClassElement elementA = importedUnit().getType('A'); 360 ClassElement elementA = importedUnit().getType('A');
371 assertThat(elementA).isMixedInAt('A {} // 2', true); 361 assertThat(elementA).isMixedInAt('A {} // 2', true);
372 } 362 }
373 363
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 await _indexTestUnit(''' 395 await _indexTestUnit('''
406 class A {} 396 class A {}
407 main() { 397 main() {
408 A(); // invalid code, but still a reference 398 A(); // invalid code, but still a reference
409 }'''); 399 }''');
410 Element element = findElement('A'); 400 Element element = findElement('A');
411 assertThat(element).isReferencedAt('A();', false); 401 assertThat(element).isReferencedAt('A();', false);
412 } 402 }
413 403
414 test_isReferencedBy_ClassElement_invocation_isQualified() async { 404 test_isReferencedBy_ClassElement_invocation_isQualified() async {
415 provider.newFile( 405 provider.newFile(_p('$testProject/lib.dart'), '''
416 _p('$testProject/lib.dart'),
417 '''
418 class A {} 406 class A {}
419 '''); 407 ''');
420 await _indexTestUnit(''' 408 await _indexTestUnit('''
421 import 'lib.dart' as p; 409 import 'lib.dart' as p;
422 main() { 410 main() {
423 p.A(); // invalid code, but still a reference 411 p.A(); // invalid code, but still a reference
424 }'''); 412 }''');
425 Element element = importedUnit().getType('A'); 413 Element element = importedUnit().getType('A');
426 assertThat(element).isReferencedAt('A();', true); 414 assertThat(element).isReferencedAt('A();', true);
427 } 415 }
428 416
429 test_isReferencedBy_ClassTypeAlias() async { 417 test_isReferencedBy_ClassTypeAlias() async {
430 await _indexTestUnit(''' 418 await _indexTestUnit('''
431 class A {} 419 class A {}
432 class B = Object with A; 420 class B = Object with A;
433 main(B p) { 421 main(B p) {
434 B v; 422 B v;
435 } 423 }
436 '''); 424 ''');
437 ClassElement element = findElement('B'); 425 ClassElement element = findElement('B');
438 assertThat(element) 426 assertThat(element)
439 ..isReferencedAt('B p) {', false) 427 ..isReferencedAt('B p) {', false)
440 ..isReferencedAt('B v;', false); 428 ..isReferencedAt('B v;', false);
441 } 429 }
442 430
443 test_isReferencedBy_CompilationUnitElement_export() async { 431 test_isReferencedBy_CompilationUnitElement_export() async {
444 provider.newFile( 432 provider.newFile(_p('$testProject/lib.dart'), '''
445 _p('$testProject/lib.dart'),
446 '''
447 library lib; 433 library lib;
448 '''); 434 ''');
449 await _indexTestUnit(''' 435 await _indexTestUnit('''
450 export 'lib.dart'; 436 export 'lib.dart';
451 '''); 437 ''');
452 LibraryElement element = testLibraryElement.exports[0].exportedLibrary; 438 LibraryElement element = testLibraryElement.exports[0].exportedLibrary;
453 assertThat(element)..isReferencedAt("'lib.dart'", true, length: 10); 439 assertThat(element)..isReferencedAt("'lib.dart'", true, length: 10);
454 } 440 }
455 441
456 test_isReferencedBy_CompilationUnitElement_import() async { 442 test_isReferencedBy_CompilationUnitElement_import() async {
457 provider.newFile( 443 provider.newFile(_p('$testProject/lib.dart'), '''
458 _p('$testProject/lib.dart'),
459 '''
460 library lib; 444 library lib;
461 '''); 445 ''');
462 await _indexTestUnit(''' 446 await _indexTestUnit('''
463 import 'lib.dart'; 447 import 'lib.dart';
464 '''); 448 ''');
465 LibraryElement element = testLibraryElement.imports[0].importedLibrary; 449 LibraryElement element = testLibraryElement.imports[0].importedLibrary;
466 assertThat(element)..isReferencedAt("'lib.dart'", true, length: 10); 450 assertThat(element)..isReferencedAt("'lib.dart'", true, length: 10);
467 } 451 }
468 452
469 test_isReferencedBy_CompilationUnitElement_part() async { 453 test_isReferencedBy_CompilationUnitElement_part() async {
470 provider.newFile(_p('$testProject/my_unit.dart'), 'part of my_lib;'); 454 provider.newFile(_p('$testProject/my_unit.dart'), 'part of my_lib;');
471 await _indexTestUnit(''' 455 await _indexTestUnit('''
472 library my_lib; 456 library my_lib;
473 part 'my_unit.dart'; 457 part 'my_unit.dart';
474 '''); 458 ''');
475 CompilationUnitElement element = testLibraryElement.parts[0]; 459 CompilationUnitElement element = testLibraryElement.parts[0];
476 assertThat(element)..isReferencedAt("'my_unit.dart';", true, length: 14); 460 assertThat(element)..isReferencedAt("'my_unit.dart';", true, length: 14);
477 } 461 }
478 462
479 test_isReferencedBy_CompilationUnitElement_part_inPart() async { 463 test_isReferencedBy_CompilationUnitElement_part_inPart() async {
480 provider.newFile(_p('$testProject/a.dart'), 'part of lib;'); 464 provider.newFile(_p('$testProject/a.dart'), 'part of lib;');
481 provider.newFile( 465 provider.newFile(_p('$testProject/b.dart'), '''
482 _p('$testProject/b.dart'),
483 '''
484 library lib; 466 library lib;
485 part 'a.dart'; 467 part 'a.dart';
486 '''); 468 ''');
487 await _indexTestUnit(''' 469 await _indexTestUnit('''
488 part 'b.dart'; 470 part 'b.dart';
489 '''); 471 ''');
490 // No exception, even though a.dart is a part of b.dart part. 472 // No exception, even though a.dart is a part of b.dart part.
491 } 473 }
492 474
493 test_isReferencedBy_ConstructorElement() async { 475 test_isReferencedBy_ConstructorElement() async {
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 print(foo()); 721 print(foo());
740 } 722 }
741 '''); 723 ''');
742 FunctionElement element = findElement('foo'); 724 FunctionElement element = findElement('foo');
743 assertThat(element) 725 assertThat(element)
744 ..isReferencedAt('foo);', false) 726 ..isReferencedAt('foo);', false)
745 ..isInvokedAt('foo());', false); 727 ..isInvokedAt('foo());', false);
746 } 728 }
747 729
748 test_isReferencedBy_FunctionElement_with_LibraryElement() async { 730 test_isReferencedBy_FunctionElement_with_LibraryElement() async {
749 provider.newFile( 731 provider.newFile(_p('$testProject/foo.dart'), r'''
750 _p('$testProject/foo.dart'),
751 r'''
752 bar() {} 732 bar() {}
753 '''); 733 ''');
754 await _indexTestUnit(''' 734 await _indexTestUnit('''
755 import "foo.dart"; 735 import "foo.dart";
756 main() { 736 main() {
757 bar(); 737 bar();
758 } 738 }
759 '''); 739 ''');
760 LibraryElement fooLibrary = testLibraryElement.imports[0].importedLibrary; 740 LibraryElement fooLibrary = testLibraryElement.imports[0].importedLibrary;
761 assertThat(fooLibrary)..isReferencedAt('"foo.dart";', true, length: 10); 741 assertThat(fooLibrary)..isReferencedAt('"foo.dart";', true, length: 10);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 int f2({int p}) => 2; 814 int f2({int p}) => 2;
835 main(bool b) { 815 main(bool b) {
836 var f = b ? f1 : f2; 816 var f = b ? f1 : f2;
837 f(p: 0); 817 f(p: 0);
838 }'''); 818 }''');
839 // We should not crash because of reference to "p" - a named parameter 819 // We should not crash because of reference to "p" - a named parameter
840 // of a synthetic LUB FunctionElement created for "f". 820 // of a synthetic LUB FunctionElement created for "f".
841 } 821 }
842 822
843 test_isReferencedBy_TopLevelVariableElement() async { 823 test_isReferencedBy_TopLevelVariableElement() async {
844 provider.newFile( 824 provider.newFile(_p('$testProject/lib.dart'), '''
845 _p('$testProject/lib.dart'),
846 '''
847 library lib; 825 library lib;
848 var V; 826 var V;
849 '''); 827 ''');
850 await _indexTestUnit(''' 828 await _indexTestUnit('''
851 import 'lib.dart' show V; // imp 829 import 'lib.dart' show V; // imp
852 import 'lib.dart' as pref; 830 import 'lib.dart' as pref;
853 main() { 831 main() {
854 pref.V = 5; // q 832 pref.V = 5; // q
855 print(pref.V); // q 833 print(pref.V); // q
856 V = 5; // nq 834 V = 5; // nq
857 print(V); // nq 835 print(V); // nq
858 }'''); 836 }''');
859 TopLevelVariableElement variable = importedUnit().topLevelVariables[0]; 837 TopLevelVariableElement variable = importedUnit().topLevelVariables[0];
860 assertThat(variable)..isReferencedAt('V; // imp', true); 838 assertThat(variable)..isReferencedAt('V; // imp', true);
861 assertThat(variable.getter) 839 assertThat(variable.getter)
862 ..isReferencedAt('V); // q', true) 840 ..isReferencedAt('V); // q', true)
863 ..isReferencedAt('V); // nq', false); 841 ..isReferencedAt('V); // nq', false);
864 assertThat(variable.setter) 842 assertThat(variable.setter)
865 ..isReferencedAt('V = 5; // q', true) 843 ..isReferencedAt('V = 5; // q', true)
866 ..isReferencedAt('V = 5; // nq', false); 844 ..isReferencedAt('V = 5; // nq', false);
867 } 845 }
868 846
869 test_isReferencedBy_TopLevelVariableElement_synthetic_hasGetterSetter() async { 847 test_isReferencedBy_TopLevelVariableElement_synthetic_hasGetterSetter() async {
870 provider.newFile( 848 provider.newFile(_p('$testProject/lib.dart'), '''
871 _p('$testProject/lib.dart'),
872 '''
873 int get V => 0; 849 int get V => 0;
874 void set V(_) {} 850 void set V(_) {}
875 '''); 851 ''');
876 await _indexTestUnit(''' 852 await _indexTestUnit('''
877 import 'lib.dart' show V; 853 import 'lib.dart' show V;
878 '''); 854 ''');
879 TopLevelVariableElement element = importedUnit().topLevelVariables[0]; 855 TopLevelVariableElement element = importedUnit().topLevelVariables[0];
880 assertThat(element).isReferencedAt('V;', true); 856 assertThat(element).isReferencedAt('V;', true);
881 } 857 }
882 858
883 test_isReferencedBy_TopLevelVariableElement_synthetic_hasSetter() async { 859 test_isReferencedBy_TopLevelVariableElement_synthetic_hasSetter() async {
884 provider.newFile( 860 provider.newFile(_p('$testProject/lib.dart'), '''
885 _p('$testProject/lib.dart'),
886 '''
887 void set V(_) {} 861 void set V(_) {}
888 '''); 862 ''');
889 await _indexTestUnit(''' 863 await _indexTestUnit('''
890 import 'lib.dart' show V; 864 import 'lib.dart' show V;
891 '''); 865 ''');
892 TopLevelVariableElement element = importedUnit().topLevelVariables[0]; 866 TopLevelVariableElement element = importedUnit().topLevelVariables[0];
893 assertThat(element).isReferencedAt('V;', true); 867 assertThat(element).isReferencedAt('V;', true);
894 } 868 }
895 869
896 test_isReferencedBy_typeInVariableList() async { 870 test_isReferencedBy_typeInVariableList() async {
(...skipping 14 matching lines...) Expand all
911 } 885 }
912 '''); 886 ''');
913 FieldElement element = findElement('field', ElementKind.FIELD); 887 FieldElement element = findElement('field', ElementKind.FIELD);
914 assertThat(element) 888 assertThat(element)
915 ..isWrittenAt('field})', true) 889 ..isWrittenAt('field})', true)
916 ..isWrittenAt('field = 5', true); 890 ..isWrittenAt('field = 5', true);
917 } 891 }
918 892
919 test_subtypes_classDeclaration() async { 893 test_subtypes_classDeclaration() async {
920 String libP = 'package:test/lib.dart;package:test/lib.dart'; 894 String libP = 'package:test/lib.dart;package:test/lib.dart';
921 provider.newFile( 895 provider.newFile(_p('$testProject/lib.dart'), '''
922 _p('$testProject/lib.dart'),
923 '''
924 class A {} 896 class A {}
925 class B {} 897 class B {}
926 class C {} 898 class C {}
927 class D {} 899 class D {}
928 class E {} 900 class E {}
929 '''); 901 ''');
930 await _indexTestUnit(''' 902 await _indexTestUnit('''
931 import 'lib.dart'; 903 import 'lib.dart';
932 904
933 class X extends A { 905 class X extends A {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 { 942 {
971 AnalysisDriverSubtype Z = 943 AnalysisDriverSubtype Z =
972 index.subtypes.singleWhere((t) => t.name == 'Z'); 944 index.subtypes.singleWhere((t) => t.name == 'Z');
973 expect(Z.supertypes, ['$libP;D', '$libP;E']); 945 expect(Z.supertypes, ['$libP;D', '$libP;E']);
974 expect(Z.members, ['methodZ']); 946 expect(Z.members, ['methodZ']);
975 } 947 }
976 } 948 }
977 949
978 test_subtypes_classTypeAlias() async { 950 test_subtypes_classTypeAlias() async {
979 String libP = 'package:test/lib.dart;package:test/lib.dart'; 951 String libP = 'package:test/lib.dart;package:test/lib.dart';
980 provider.newFile( 952 provider.newFile(_p('$testProject/lib.dart'), '''
981 _p('$testProject/lib.dart'),
982 '''
983 class A {} 953 class A {}
984 class B {} 954 class B {}
985 class C {} 955 class C {}
986 class D {} 956 class D {}
987 '''); 957 ''');
988 await _indexTestUnit(''' 958 await _indexTestUnit('''
989 import 'lib.dart'; 959 import 'lib.dart';
990 960
991 class X = A with B, C; 961 class X = A with B, C;
992 class Y = A with B implements C, D; 962 class Y = A with B implements C, D;
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 final bool isQualified; 1330 final bool isQualified;
1361 1331
1362 _Relation(this.kind, this.offset, this.length, this.isQualified); 1332 _Relation(this.kind, this.offset, this.length, this.isQualified);
1363 1333
1364 @override 1334 @override
1365 String toString() { 1335 String toString() {
1366 return '_Relation{kind: $kind, offset: $offset, length: $length, ' 1336 return '_Relation{kind: $kind, offset: $offset, length: $length, '
1367 'isQualified: $isQualified}lified)'; 1337 'isQualified: $isQualified}lified)';
1368 } 1338 }
1369 } 1339 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/dart/analysis/file_state_test.dart ('k') | pkg/analyzer/test/src/dart/analysis/search_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698