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

Side by Side Diff: pkg/analyzer/test/src/summary/linker_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 'package:analyzer/dart/element/type.dart'; 5 import 'package:analyzer/dart/element/type.dart';
6 import 'package:analyzer/src/dart/element/element.dart'; 6 import 'package:analyzer/src/dart/element/element.dart';
7 import 'package:analyzer/src/summary/format.dart'; 7 import 'package:analyzer/src/summary/format.dart';
8 import 'package:analyzer/src/summary/idl.dart'; 8 import 'package:analyzer/src/summary/idl.dart';
9 import 'package:analyzer/src/summary/link.dart'; 9 import 'package:analyzer/src/summary/link.dart';
10 import 'package:test/test.dart'; 10 import 'package:test/test.dart';
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 class C extends B { 192 class C extends B {
193 var c; 193 var c;
194 } 194 }
195 '''); 195 ''');
196 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); 196 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri);
197 library.libraryCycleForLink.ensureLinked(); 197 library.libraryCycleForLink.ensureLinked();
198 // No assertions--just make sure it doesn't crash. 198 // No assertions--just make sure it doesn't crash.
199 } 199 }
200 200
201 void test_bundle_refers_to_bundle() { 201 void test_bundle_refers_to_bundle() {
202 var bundle1 = createPackageBundle( 202 var bundle1 = createPackageBundle('''
203 '''
204 var x = 0; 203 var x = 0;
205 ''', 204 ''', path: '/a.dart');
206 path: '/a.dart');
207 addBundle('/a.ds', bundle1); 205 addBundle('/a.ds', bundle1);
208 var bundle2 = createPackageBundle( 206 var bundle2 = createPackageBundle('''
209 '''
210 import "a.dart"; 207 import "a.dart";
211 var y = x; 208 var y = x;
212 ''', 209 ''', path: '/b.dart');
213 path: '/b.dart');
214 expect(bundle2.dependencies, hasLength(1)); 210 expect(bundle2.dependencies, hasLength(1));
215 expect(bundle2.dependencies[0].summaryPath, '/a.ds'); 211 expect(bundle2.dependencies[0].summaryPath, '/a.ds');
216 expect(bundle2.dependencies[0].apiSignature, bundle1.apiSignature); 212 expect(bundle2.dependencies[0].apiSignature, bundle1.apiSignature);
217 addBundle('/a.ds', bundle1); 213 addBundle('/a.ds', bundle1);
218 addBundle('/b.ds', bundle2); 214 addBundle('/b.ds', bundle2);
219 createLinker(''' 215 createLinker('''
220 import "b.dart"; 216 import "b.dart";
221 var z = y; 217 var z = y;
222 '''); 218 ''');
223 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); 219 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 expect(parameterAFT.isCovariant, isTrue); 255 expect(parameterAFT.isCovariant, isTrue);
260 expect(parameterAFT.inheritsCovariant, isFalse); 256 expect(parameterAFT.inheritsCovariant, isFalse);
261 ClassElementForLink classB = testLibrary.getContainedName('B'); 257 ClassElementForLink classB = testLibrary.getContainedName('B');
262 MethodElementForLink methodBF = classB.getContainedName('f'); 258 MethodElementForLink methodBF = classB.getContainedName('f');
263 ParameterElementForLink parameterBFT = methodBF.parameters[0]; 259 ParameterElementForLink parameterBFT = methodBF.parameters[0];
264 expect(parameterAFT.isCovariant, isTrue); 260 expect(parameterAFT.isCovariant, isTrue);
265 expect(parameterBFT.inheritsCovariant, isTrue); 261 expect(parameterBFT.inheritsCovariant, isTrue);
266 } 262 }
267 263
268 void test_createPackageBundle_withPackageUri() { 264 void test_createPackageBundle_withPackageUri() {
269 PackageBundle bundle = createPackageBundle( 265 PackageBundle bundle = createPackageBundle('''
270 '''
271 class B { 266 class B {
272 void f(int i) {} 267 void f(int i) {}
273 } 268 }
274 class C extends B { 269 class C extends B {
275 f(i) {} // Inferred param type: int 270 f(i) {} // Inferred param type: int
276 } 271 }
277 ''', 272 ''', uri: 'package:foo/bar.dart');
278 uri: 'package:foo/bar.dart');
279 UnlinkedExecutable cf = bundle.unlinkedUnits[0].classes[1].executables[0]; 273 UnlinkedExecutable cf = bundle.unlinkedUnits[0].classes[1].executables[0];
280 UnlinkedParam cfi = cf.parameters[0]; 274 UnlinkedParam cfi = cf.parameters[0];
281 expect(cfi.inferredTypeSlot, isNot(0)); 275 expect(cfi.inferredTypeSlot, isNot(0));
282 EntityRef typeRef = _lookupInferredType( 276 EntityRef typeRef = _lookupInferredType(
283 bundle.linkedLibraries[0].units[0], cfi.inferredTypeSlot); 277 bundle.linkedLibraries[0].units[0], cfi.inferredTypeSlot);
284 expect(typeRef, isNotNull); 278 expect(typeRef, isNotNull);
285 expect(bundle.unlinkedUnits[0].references[typeRef.reference].name, 'int'); 279 expect(bundle.unlinkedUnits[0].references[typeRef.reference].name, 'int');
286 } 280 }
287 281
288 void test_getContainedName_nonStaticField() { 282 void test_getContainedName_nonStaticField() {
(...skipping 18 matching lines...) Expand all
307 } 301 }
308 302
309 void test_getContainedName_nonStaticSetter() { 303 void test_getContainedName_nonStaticSetter() {
310 createLinker('class C { void set s(value) {} }'); 304 createLinker('class C { void set s(value) {} }');
311 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); 305 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri);
312 ClassElementForLink_Class c = library.getContainedName('C'); 306 ClassElementForLink_Class c = library.getContainedName('C');
313 expect(c.getContainedName('s='), isNot(isUndefined)); 307 expect(c.getContainedName('s='), isNot(isUndefined));
314 } 308 }
315 309
316 void test_inferredType_closure_fromBundle() { 310 void test_inferredType_closure_fromBundle() {
317 var bundle = createPackageBundle( 311 var bundle = createPackageBundle('''
318 '''
319 var x = () {}; 312 var x = () {};
320 ''', 313 ''', path: '/a.dart');
321 path: '/a.dart');
322 addBundle('/a.ds', bundle); 314 addBundle('/a.ds', bundle);
323 createLinker(''' 315 createLinker('''
324 import 'a.dart'; 316 import 'a.dart';
325 var y = x; 317 var y = x;
326 '''); 318 ''');
327 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); 319 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri);
328 expect(_getVariable(library.getContainedName('y')).inferredType.toString(), 320 expect(_getVariable(library.getContainedName('y')).inferredType.toString(),
329 '() → dynamic'); 321 '() → dynamic');
330 } 322 }
331 323
332 void test_inferredType_closure_fromBundle_identifierSequence() { 324 void test_inferredType_closure_fromBundle_identifierSequence() {
333 var bundle = createPackageBundle( 325 var bundle = createPackageBundle('''
334 '''
335 class C { 326 class C {
336 static final x = (D d) => d.e; 327 static final x = (D d) => d.e;
337 } 328 }
338 class D { 329 class D {
339 E e; 330 E e;
340 } 331 }
341 class E {} 332 class E {}
342 ''', 333 ''', path: '/a.dart');
343 path: '/a.dart');
344 addBundle('/a.ds', bundle); 334 addBundle('/a.ds', bundle);
345 createLinker(''' 335 createLinker('''
346 import 'a.dart'; 336 import 'a.dart';
347 var y = C.x; 337 var y = C.x;
348 '''); 338 ''');
349 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); 339 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri);
350 expect(_getVariable(library.getContainedName('y')).inferredType.toString(), 340 expect(_getVariable(library.getContainedName('y')).inferredType.toString(),
351 '(D) → dynamic'); 341 '(D) → dynamic');
352 } 342 }
353 343
354 void test_inferredType_implicitFunctionTypeIndices() { 344 void test_inferredType_implicitFunctionTypeIndices() {
355 var bundle = createPackageBundle( 345 var bundle = createPackageBundle('''
356 '''
357 class A { 346 class A {
358 void foo(void bar(int arg)) {} 347 void foo(void bar(int arg)) {}
359 } 348 }
360 class B extends A { 349 class B extends A {
361 void foo(bar) {} 350 void foo(bar) {}
362 } 351 }
363 ''', 352 ''', path: '/a.dart');
364 path: '/a.dart');
365 addBundle('/a.ds', bundle); 353 addBundle('/a.ds', bundle);
366 createLinker(''' 354 createLinker('''
367 import 'a.dart'; 355 import 'a.dart';
368 class C extends B { 356 class C extends B {
369 void foo(bar) {} 357 void foo(bar) {}
370 } 358 }
371 '''); 359 ''');
372 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); 360 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri);
373 library.libraryCycleForLink.ensureLinked(); 361 library.libraryCycleForLink.ensureLinked();
374 ClassElementForLink_Class cls = library.getContainedName('C'); 362 ClassElementForLink_Class cls = library.getContainedName('C');
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 } 440 }
453 '''); 441 ''');
454 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); 442 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri);
455 library.libraryCycleForLink.ensureLinked(); 443 library.libraryCycleForLink.ensureLinked();
456 ClassElementForLink_Class cls = library.getContainedName('C'); 444 ClassElementForLink_Class cls = library.getContainedName('C');
457 expect(cls.methods, hasLength(1)); 445 expect(cls.methods, hasLength(1));
458 expect(cls.methods[0].returnType.toString(), 'void'); 446 expect(cls.methods[0].returnType.toString(), 'void');
459 } 447 }
460 448
461 void test_inferredType_parameter_genericFunctionType() { 449 void test_inferredType_parameter_genericFunctionType() {
462 var bundle = createPackageBundle( 450 var bundle = createPackageBundle('''
463 '''
464 class A<T> { 451 class A<T> {
465 A<R> map<R>(R Function(T) f) => null; 452 A<R> map<R>(R Function(T) f) => null;
466 } 453 }
467 ''', 454 ''', path: '/a.dart');
468 path: '/a.dart');
469 addBundle('/a.ds', bundle); 455 addBundle('/a.ds', bundle);
470 createLinker(''' 456 createLinker('''
471 import 'a.dart'; 457 import 'a.dart';
472 class C extends A<int> { 458 class C extends A<int> {
473 map<R2>(f) => null; 459 map<R2>(f) => null;
474 } 460 }
475 '''); 461 ''');
476 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); 462 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri);
477 library.libraryCycleForLink.ensureLinked(); 463 library.libraryCycleForLink.ensureLinked();
478 ClassElementForLink_Class c = library.getContainedName('C'); 464 ClassElementForLink_Class c = library.getContainedName('C');
(...skipping 30 matching lines...) Expand all
509 expect( 495 expect(
510 _getVariable(linker 496 _getVariable(linker
511 .getLibrary(linkerInputs.testDartUri) 497 .getLibrary(linkerInputs.testDartUri)
512 .getContainedName('y')) 498 .getContainedName('y'))
513 .inferredType 499 .inferredType
514 .toString(), 500 .toString(),
515 'dynamic'); 501 'dynamic');
516 } 502 }
517 503
518 void test_inferredTypeFromOutsideBuildUnit_dynamic() { 504 void test_inferredTypeFromOutsideBuildUnit_dynamic() {
519 var bundle = createPackageBundle( 505 var bundle = createPackageBundle('''
520 '''
521 var x; 506 var x;
522 var y = x; // Inferred type: dynamic 507 var y = x; // Inferred type: dynamic
523 ''', 508 ''', path: '/a.dart');
524 path: '/a.dart');
525 addBundle('/a.ds', bundle); 509 addBundle('/a.ds', bundle);
526 createLinker(''' 510 createLinker('''
527 import 'a.dart'; 511 import 'a.dart';
528 var z = y; // Inferred type: dynamic 512 var z = y; // Inferred type: dynamic
529 '''); 513 ''');
530 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); 514 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri);
531 expect(_getVariable(library.getContainedName('z')).inferredType.toString(), 515 expect(_getVariable(library.getContainedName('z')).inferredType.toString(),
532 'dynamic'); 516 'dynamic');
533 } 517 }
534 518
535 void test_inferredTypeFromOutsideBuildUnit_instanceField() { 519 void test_inferredTypeFromOutsideBuildUnit_instanceField() {
536 var bundle = createPackageBundle( 520 var bundle = createPackageBundle('''
537 '''
538 class C { 521 class C {
539 var f = 0; // Inferred type: int 522 var f = 0; // Inferred type: int
540 } 523 }
541 ''', 524 ''', path: '/a.dart');
542 path: '/a.dart');
543 addBundle('/a.ds', bundle); 525 addBundle('/a.ds', bundle);
544 createLinker(''' 526 createLinker('''
545 import 'a.dart'; 527 import 'a.dart';
546 var x = new C().f; // Inferred type: dynamic 528 var x = new C().f; // Inferred type: dynamic
547 '''); 529 ''');
548 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); 530 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri);
549 expect(_getVariable(library.getContainedName('x')).inferredType.toString(), 531 expect(_getVariable(library.getContainedName('x')).inferredType.toString(),
550 'dynamic'); 532 'dynamic');
551 } 533 }
552 534
553 void test_inferredTypeFromOutsideBuildUnit_instanceField_toInstanceField() { 535 void test_inferredTypeFromOutsideBuildUnit_instanceField_toInstanceField() {
554 var bundle = createPackageBundle( 536 var bundle = createPackageBundle('''
555 '''
556 class C { 537 class C {
557 var f = 0; // Inferred type: int 538 var f = 0; // Inferred type: int
558 } 539 }
559 ''', 540 ''', path: '/a.dart');
560 path: '/a.dart');
561 addBundle('/a.ds', bundle); 541 addBundle('/a.ds', bundle);
562 createLinker(''' 542 createLinker('''
563 import 'a.dart'; 543 import 'a.dart';
564 class D { 544 class D {
565 var g = new C().f; // Inferred type: dynamic 545 var g = new C().f; // Inferred type: dynamic
566 } 546 }
567 '''); 547 ''');
568 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); 548 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri);
569 ClassElementForLink_Class classD = library.getContainedName('D'); 549 ClassElementForLink_Class classD = library.getContainedName('D');
570 expect(classD.fields[0].inferredType.toString(), 'dynamic'); 550 expect(classD.fields[0].inferredType.toString(), 'dynamic');
571 } 551 }
572 552
573 void test_inferredTypeFromOutsideBuildUnit_methodParamType_viaInheritance() { 553 void test_inferredTypeFromOutsideBuildUnit_methodParamType_viaInheritance() {
574 var bundle = createPackageBundle( 554 var bundle = createPackageBundle('''
575 '''
576 class B { 555 class B {
577 void f(int i) {} 556 void f(int i) {}
578 } 557 }
579 class C extends B { 558 class C extends B {
580 f(i) {} // Inferred param type: int 559 f(i) {} // Inferred param type: int
581 } 560 }
582 ''', 561 ''', path: '/a.dart');
583 path: '/a.dart');
584 addBundle('/a.ds', bundle); 562 addBundle('/a.ds', bundle);
585 createLinker(''' 563 createLinker('''
586 import 'a.dart'; 564 import 'a.dart';
587 class D extends C { 565 class D extends C {
588 f(i) {} // Inferred param type: int 566 f(i) {} // Inferred param type: int
589 } 567 }
590 '''); 568 ''');
591 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); 569 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri);
592 library.libraryCycleForLink.ensureLinked(); 570 library.libraryCycleForLink.ensureLinked();
593 ClassElementForLink_Class cls = library.getContainedName('D'); 571 ClassElementForLink_Class cls = library.getContainedName('D');
594 expect(cls.methods, hasLength(1)); 572 expect(cls.methods, hasLength(1));
595 var method = cls.methods[0]; 573 var method = cls.methods[0];
596 expect(method.parameters, hasLength(1)); 574 expect(method.parameters, hasLength(1));
597 expect(method.parameters[0].type.toString(), 'int'); 575 expect(method.parameters[0].type.toString(), 'int');
598 } 576 }
599 577
600 void test_inferredTypeFromOutsideBuildUnit_methodReturnType_viaCall() { 578 void test_inferredTypeFromOutsideBuildUnit_methodReturnType_viaCall() {
601 var bundle = createPackageBundle( 579 var bundle = createPackageBundle('''
602 '''
603 class B { 580 class B {
604 int f() => 0; 581 int f() => 0;
605 } 582 }
606 class C extends B { 583 class C extends B {
607 f() => 1; // Inferred return type: int 584 f() => 1; // Inferred return type: int
608 } 585 }
609 ''', 586 ''', path: '/a.dart');
610 path: '/a.dart');
611 addBundle('/a.ds', bundle); 587 addBundle('/a.ds', bundle);
612 createLinker(''' 588 createLinker('''
613 import 'a.dart'; 589 import 'a.dart';
614 var x = new C().f(); // Inferred type: int 590 var x = new C().f(); // Inferred type: int
615 '''); 591 ''');
616 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); 592 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri);
617 expect(_getVariable(library.getContainedName('x')).inferredType.toString(), 593 expect(_getVariable(library.getContainedName('x')).inferredType.toString(),
618 'int'); 594 'int');
619 } 595 }
620 596
621 void test_inferredTypeFromOutsideBuildUnit_methodReturnType_viaInheritance() { 597 void test_inferredTypeFromOutsideBuildUnit_methodReturnType_viaInheritance() {
622 var bundle = createPackageBundle( 598 var bundle = createPackageBundle('''
623 '''
624 class B { 599 class B {
625 int f() => 0; 600 int f() => 0;
626 } 601 }
627 class C extends B { 602 class C extends B {
628 f() => 1; // Inferred return type: int 603 f() => 1; // Inferred return type: int
629 } 604 }
630 ''', 605 ''', path: '/a.dart');
631 path: '/a.dart');
632 addBundle('/a.ds', bundle); 606 addBundle('/a.ds', bundle);
633 createLinker(''' 607 createLinker('''
634 import 'a.dart'; 608 import 'a.dart';
635 class D extends C { 609 class D extends C {
636 f() => 2; //Inferred return type: int 610 f() => 2; //Inferred return type: int
637 } 611 }
638 '''); 612 ''');
639 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); 613 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri);
640 library.libraryCycleForLink.ensureLinked(); 614 library.libraryCycleForLink.ensureLinked();
641 ClassElementForLink_Class cls = library.getContainedName('D'); 615 ClassElementForLink_Class cls = library.getContainedName('D');
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 */ 963 */
990 EntityRef _lookupInferredType(LinkedUnit unit, int slot) { 964 EntityRef _lookupInferredType(LinkedUnit unit, int slot) {
991 for (EntityRef ref in unit.types) { 965 for (EntityRef ref in unit.types) {
992 if (ref.slot == slot) { 966 if (ref.slot == slot) {
993 return ref; 967 return ref;
994 } 968 }
995 } 969 }
996 return null; 970 return null;
997 } 971 }
998 } 972 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/dart/sdk/sdk_test.dart ('k') | pkg/analyzer/test/src/summary/resynthesize_common.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698