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

Side by Side Diff: pkg/analyzer/test/src/summary/summary_common.dart

Issue 1633863002: Support for constructor references in constant serializer and prelinker. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Record default constructor references as class references Created 4 years, 11 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) 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.summary.summary_common; 5 library analyzer.test.src.summary.summary_common;
6 6
7 import 'package:analyzer/analyzer.dart'; 7 import 'package:analyzer/analyzer.dart';
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/generated/engine.dart'; 10 import 'package:analyzer/src/generated/engine.dart';
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 * to the compilation unit within which the [typeRef] appears; if not 461 * to the compilation unit within which the [typeRef] appears; if not
462 * specified they are assumed to refer to the defining compilation unit. 462 * specified they are assumed to refer to the defining compilation unit.
463 * [expectedTargetUnit] is the index of the compilation unit in which the 463 * [expectedTargetUnit] is the index of the compilation unit in which the
464 * target of the [typeRef] is expected to appear; if not specified it is 464 * target of the [typeRef] is expected to appear; if not specified it is
465 * assumed to be the defining compilation unit. [numTypeParameters] is the 465 * assumed to be the defining compilation unit. [numTypeParameters] is the
466 * number of type parameters of the thing being referred to. 466 * number of type parameters of the thing being referred to.
467 */ 467 */
468 void checkTypeRef(EntityRef typeRef, String absoluteUri, String relativeUri, 468 void checkTypeRef(EntityRef typeRef, String absoluteUri, String relativeUri,
469 String expectedName, 469 String expectedName,
470 {String expectedPrefix, 470 {String expectedPrefix,
471 List<_PrefixExpectation> prefixExpectations,
471 bool allowTypeParameters: false, 472 bool allowTypeParameters: false,
472 ReferenceKind expectedKind: ReferenceKind.classOrEnum, 473 ReferenceKind expectedKind: ReferenceKind.classOrEnum,
473 int expectedTargetUnit: 0, 474 int expectedTargetUnit: 0,
474 LinkedUnit linkedSourceUnit, 475 LinkedUnit linkedSourceUnit,
475 UnlinkedUnit unlinkedSourceUnit, 476 UnlinkedUnit unlinkedSourceUnit,
476 int numTypeParameters: 0}) { 477 int numTypeParameters: 0}) {
477 linkedSourceUnit ??= definingUnit; 478 linkedSourceUnit ??= definingUnit;
478 expect(typeRef, new isInstanceOf<EntityRef>()); 479 expect(typeRef, new isInstanceOf<EntityRef>());
479 expect(typeRef.paramReference, 0); 480 expect(typeRef.paramReference, 0);
480 int index = typeRef.reference; 481 int index = typeRef.reference;
481 if (!allowTypeParameters) { 482 if (!allowTypeParameters) {
482 expect(typeRef.typeArguments, isEmpty); 483 expect(typeRef.typeArguments, isEmpty);
483 } 484 }
484 UnlinkedReference reference = checkTypeRefCommonElements( 485 UnlinkedReference reference = checkTypeRefCommonElements(
485 index, 486 index,
486 absoluteUri, 487 absoluteUri,
487 relativeUri, 488 relativeUri,
488 expectedName, 489 expectedName,
489 expectedKind, 490 expectedKind,
490 expectedTargetUnit, 491 expectedTargetUnit,
491 linkedSourceUnit, 492 linkedSourceUnit,
492 unlinkedSourceUnit, 493 unlinkedSourceUnit,
493 numTypeParameters); 494 numTypeParameters);
494 expect(reference, isNotNull, 495 expect(reference, isNotNull,
495 reason: 'Unlinked type refs must refer to an explicit reference'); 496 reason: 'Unlinked type refs must refer to an explicit reference');
496 if (expectedKind == ReferenceKind.unresolved && !checkAstDerivedData) { 497 if (expectedKind == ReferenceKind.unresolved && !checkAstDerivedData) {
497 // summarize_elements.dart isn't yet able to record the prefix of 498 // summarize_elements.dart isn't yet able to record the prefix of
498 // unresolved references. TODO(paulberry): fix this. 499 // unresolved references. TODO(paulberry): fix this.
499 expect(reference.prefixReference, 0); 500 expect(reference.prefixReference, 0);
500 } else if (expectedPrefix == null) { 501 } else if (expectedPrefix != null) {
502 checkPrefix(reference.prefixReference, expectedPrefix);
503 } else if (prefixExpectations != null) {
504 for (_PrefixExpectation expectation in prefixExpectations) {
505 expect(reference.prefixReference, isNot(0));
506 reference = checkTypeRefCommonElements(
507 reference.prefixReference,
508 expectation.inLibraryDefiningUnit ? null : absoluteUri,
509 expectation.inLibraryDefiningUnit ? null : relativeUri,
510 expectation.name,
511 expectation.kind,
512 expectedTargetUnit,
513 linkedSourceUnit,
514 unlinkedSourceUnit,
515 expectation.numTypeParameters);
516 }
501 expect(reference.prefixReference, 0); 517 expect(reference.prefixReference, 0);
502 } else { 518 } else {
503 checkPrefix(reference.prefixReference, expectedPrefix); 519 expect(reference.prefixReference, 0);
504 } 520 }
505 } 521 }
506 522
507 /** 523 /**
508 * Check the data structures that are common between [checkTypeRef] and 524 * Check the data structures that are common between [checkTypeRef] and
509 * [checkLinkedTypeRef]. If the type reference in question is an explicit 525 * [checkLinkedTypeRef]. If the type reference in question is an explicit
510 * reference, return the [UnlinkedReference] that is used to make the 526 * reference, return the [UnlinkedReference] that is used to make the
511 * explicit reference. If the type reference in question is an implicit 527 * explicit reference. If the type reference in question is an implicit
512 * reference, return `null`. 528 * reference, return `null`.
513 */ 529 */
(...skipping 991 matching lines...) Expand 10 before | Expand all | Expand 10 after
1505 _assertUnlinkedConst(variable.constExpr, operators: [ 1521 _assertUnlinkedConst(variable.constExpr, operators: [
1506 UnlinkedConstOperation.pushInt, 1522 UnlinkedConstOperation.pushInt,
1507 UnlinkedConstOperation.pushNull, 1523 UnlinkedConstOperation.pushNull,
1508 UnlinkedConstOperation.identical 1524 UnlinkedConstOperation.identical
1509 ], ints: [ 1525 ], ints: [
1510 42 1526 42
1511 ]); 1527 ]);
1512 } 1528 }
1513 1529
1514 test_constExpr_invokeConstructor_named() { 1530 test_constExpr_invokeConstructor_named() {
1515 if (checkAstDerivedData) {
1516 // TODO(scheglov) at the moment we cannot link class member references
1517 return;
1518 }
1519 UnlinkedVariable variable = serializeVariableText(''' 1531 UnlinkedVariable variable = serializeVariableText('''
1520 class C { 1532 class C {
1521 const C.named(); 1533 const C.named();
1522 } 1534 }
1523 const v = const C.named(); 1535 const v = const C.named();
1524 '''); 1536 ''');
1525 _assertUnlinkedConst(variable.constExpr, operators: [ 1537 _assertUnlinkedConst(variable.constExpr, operators: [
1526 UnlinkedConstOperation.invokeConstructor, 1538 UnlinkedConstOperation.invokeConstructor,
1527 ], ints: [ 1539 ], ints: [
1528 0, 1540 0,
1529 0 1541 0
1530 ], strings: [
1531 'named'
1532 ], referenceValidators: [ 1542 ], referenceValidators: [
1533 (EntityRef r) => checkTypeRef(r, null, null, 'C', 1543 (EntityRef r) => checkTypeRef(r, null, null, 'named',
1534 expectedKind: ReferenceKind.classOrEnum) 1544 expectedKind: ReferenceKind.constructor,
1545 prefixExpectations: [
1546 new _PrefixExpectation(ReferenceKind.classOrEnum, 'C')
1547 ])
1535 ]); 1548 ]);
1536 } 1549 }
1537 1550
1538 test_constExpr_invokeConstructor_named_imported() { 1551 test_constExpr_invokeConstructor_named_imported() {
1539 if (checkAstDerivedData) {
1540 // TODO(scheglov) at the moment we cannot link class member references
1541 return;
1542 }
1543 addNamedSource( 1552 addNamedSource(
1544 '/a.dart', 1553 '/a.dart',
1545 ''' 1554 '''
1546 class C { 1555 class C {
1547 const C.named(); 1556 const C.named();
1548 } 1557 }
1549 '''); 1558 ''');
1550 UnlinkedVariable variable = serializeVariableText(''' 1559 UnlinkedVariable variable = serializeVariableText('''
1551 import 'a.dart'; 1560 import 'a.dart';
1552 const v = const C.named(); 1561 const v = const C.named();
1553 '''); 1562 ''');
1554 _assertUnlinkedConst(variable.constExpr, operators: [ 1563 _assertUnlinkedConst(variable.constExpr, operators: [
1555 UnlinkedConstOperation.invokeConstructor, 1564 UnlinkedConstOperation.invokeConstructor,
1556 ], ints: [ 1565 ], ints: [
1557 0, 1566 0,
1558 0 1567 0
1559 ], strings: [
1560 'named'
1561 ], referenceValidators: [ 1568 ], referenceValidators: [
1562 (EntityRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'C', 1569 (EntityRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'named',
1563 expectedKind: ReferenceKind.classOrEnum) 1570 expectedKind: ReferenceKind.constructor,
1571 prefixExpectations: [
1572 new _PrefixExpectation(ReferenceKind.classOrEnum, 'C')
1573 ])
1564 ]); 1574 ]);
1565 } 1575 }
1566 1576
1567 test_constExpr_invokeConstructor_named_imported_withPrefix() { 1577 test_constExpr_invokeConstructor_named_imported_withPrefix() {
1568 addNamedSource( 1578 addNamedSource(
1569 '/a.dart', 1579 '/a.dart',
1570 ''' 1580 '''
1571 class C { 1581 class C {
1572 const C.named(); 1582 const C.named();
1573 } 1583 }
1574 '''); 1584 ''');
1575 UnlinkedVariable variable = serializeVariableText(''' 1585 UnlinkedVariable variable = serializeVariableText('''
1576 import 'a.dart' as p; 1586 import 'a.dart' as p;
1577 const v = const p.C.named(); 1587 const v = const p.C.named();
1578 '''); 1588 ''');
1579 _assertUnlinkedConst(variable.constExpr, operators: [ 1589 _assertUnlinkedConst(variable.constExpr, operators: [
1580 UnlinkedConstOperation.invokeConstructor, 1590 UnlinkedConstOperation.invokeConstructor,
1581 ], ints: [ 1591 ], ints: [
1582 0, 1592 0,
1583 0 1593 0
1584 ], strings: [
1585 'named'
1586 ], referenceValidators: [ 1594 ], referenceValidators: [
1587 (EntityRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'C', 1595 (EntityRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'named',
1588 expectedKind: ReferenceKind.classOrEnum, expectedPrefix: 'p') 1596 expectedKind: ReferenceKind.constructor,
1597 prefixExpectations: [
1598 new _PrefixExpectation(ReferenceKind.classOrEnum, 'C'),
1599 new _PrefixExpectation(ReferenceKind.prefix, 'p',
1600 inLibraryDefiningUnit: true)
1601 ])
1589 ]); 1602 ]);
1590 } 1603 }
1591 1604
1592 test_constExpr_invokeConstructor_unnamed() { 1605 test_constExpr_invokeConstructor_unnamed() {
1593 UnlinkedVariable variable = serializeVariableText(''' 1606 UnlinkedVariable variable = serializeVariableText('''
1594 class C { 1607 class C {
1595 const C(a, b, c, d, {e, f, g}); 1608 const C(a, b, c, d, {e, f, g});
1596 } 1609 }
1597 const v = const C(11, 22, 3.3, '444', e: 55, g: '777', f: 66); 1610 const v = const C(11, 22, 3.3, '444', e: 55, g: '777', f: 66);
1598 '''); 1611 ''');
(...skipping 17 matching lines...) Expand all
1616 66, 1629 66,
1617 3, 1630 3,
1618 4, 1631 4,
1619 ], doubles: [ 1632 ], doubles: [
1620 3.3 1633 3.3
1621 ], strings: [ 1634 ], strings: [
1622 '444', 1635 '444',
1623 '777', 1636 '777',
1624 'e', 1637 'e',
1625 'g', 1638 'g',
1626 'f', 1639 'f'
1627 ''
1628 ], referenceValidators: [ 1640 ], referenceValidators: [
1629 (EntityRef r) => checkTypeRef(r, null, null, 'C', 1641 (EntityRef r) => checkTypeRef(r, null, null, 'C',
1630 expectedKind: ReferenceKind.classOrEnum) 1642 expectedKind: ReferenceKind.classOrEnum)
1631 ]); 1643 ]);
1632 } 1644 }
1633 1645
1646 test_constExpr_invokeConstructor_unnamed_imported() {
1647 addNamedSource(
1648 '/a.dart',
1649 '''
1650 class C {
1651 const C();
1652 }
1653 ''');
1654 UnlinkedVariable variable = serializeVariableText('''
1655 import 'a.dart';
1656 const v = const C();
1657 ''');
1658 _assertUnlinkedConst(variable.constExpr, operators: [
1659 UnlinkedConstOperation.invokeConstructor,
1660 ], ints: [
1661 0,
1662 0
1663 ], referenceValidators: [
1664 (EntityRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'C',
1665 expectedKind: ReferenceKind.classOrEnum)
1666 ]);
1667 }
1668
1669 test_constExpr_invokeConstructor_unnamed_imported_withPrefix() {
1670 addNamedSource(
1671 '/a.dart',
1672 '''
1673 class C {
1674 const C();
1675 }
1676 ''');
1677 UnlinkedVariable variable = serializeVariableText('''
1678 import 'a.dart' as p;
1679 const v = const p.C();
1680 ''');
1681 _assertUnlinkedConst(variable.constExpr, operators: [
1682 UnlinkedConstOperation.invokeConstructor,
1683 ], ints: [
1684 0,
1685 0
1686 ], referenceValidators: [
1687 (EntityRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'C',
1688 expectedKind: ReferenceKind.classOrEnum,
1689 prefixExpectations: [
1690 new _PrefixExpectation(ReferenceKind.prefix, 'p',
1691 inLibraryDefiningUnit: true)
1692 ])
1693 ]);
1694 }
1695
1634 test_constExpr_length() { 1696 test_constExpr_length() {
1635 UnlinkedVariable variable = 1697 UnlinkedVariable variable =
1636 serializeVariableText('const v = "abc".length;'); 1698 serializeVariableText('const v = "abc".length;');
1637 _assertUnlinkedConst(variable.constExpr, operators: [ 1699 _assertUnlinkedConst(variable.constExpr, operators: [
1638 UnlinkedConstOperation.pushString, 1700 UnlinkedConstOperation.pushString,
1639 UnlinkedConstOperation.length 1701 UnlinkedConstOperation.length
1640 ], strings: [ 1702 ], strings: [
1641 'abc' 1703 'abc'
1642 ]); 1704 ]);
1643 } 1705 }
(...skipping 1607 matching lines...) Expand 10 before | Expand all | Expand 10 after
3251 expect(cls.executables[0].parameters[0].inferredTypeSlot, 0); 3313 expect(cls.executables[0].parameters[0].inferredTypeSlot, 0);
3252 } 3314 }
3253 3315
3254 test_field_inferred_type_nonstatic_explicit_initialized() { 3316 test_field_inferred_type_nonstatic_explicit_initialized() {
3255 UnlinkedVariable v = serializeClassText('class C { num v = 0; }').fields[0]; 3317 UnlinkedVariable v = serializeClassText('class C { num v = 0; }').fields[0];
3256 expect(v.inferredTypeSlot, 0); 3318 expect(v.inferredTypeSlot, 0);
3257 } 3319 }
3258 3320
3259 test_field_inferred_type_nonstatic_explicit_uninitialized() { 3321 test_field_inferred_type_nonstatic_explicit_uninitialized() {
3260 UnlinkedVariable v = serializeClassText( 3322 UnlinkedVariable v = serializeClassText(
3261 'class C extends D { num v; } abstract class D { int get v; }', 3323 'class C extends D { num v; } abstract class D { int get v; }',
3262 className: 'C', 3324 className: 'C',
3263 allowErrors: true).fields[0]; 3325 allowErrors: true)
3326 .fields[0];
3264 expect(v.inferredTypeSlot, 0); 3327 expect(v.inferredTypeSlot, 0);
3265 } 3328 }
3266 3329
3267 test_field_inferred_type_nonstatic_implicit_initialized() { 3330 test_field_inferred_type_nonstatic_implicit_initialized() {
3268 UnlinkedVariable v = serializeClassText('class C { var v = 0; }').fields[0]; 3331 UnlinkedVariable v = serializeClassText('class C { var v = 0; }').fields[0];
3269 checkInferredTypeSlot(v.inferredTypeSlot, 'dart:core', 'dart:core', 'int'); 3332 checkInferredTypeSlot(v.inferredTypeSlot, 'dart:core', 'dart:core', 'int');
3270 } 3333 }
3271 3334
3272 test_field_inferred_type_nonstatic_implicit_uninitialized() { 3335 test_field_inferred_type_nonstatic_implicit_uninitialized() {
3273 UnlinkedVariable v = serializeClassText( 3336 UnlinkedVariable v = serializeClassText(
3274 'class C extends D { var v; } abstract class D { int get v; }', 3337 'class C extends D { var v; } abstract class D { int get v; }',
3275 className: 'C').fields[0]; 3338 className: 'C')
3339 .fields[0];
3276 checkInferredTypeSlot(v.inferredTypeSlot, 'dart:core', 'dart:core', 'int'); 3340 checkInferredTypeSlot(v.inferredTypeSlot, 'dart:core', 'dart:core', 'int');
3277 } 3341 }
3278 3342
3279 test_field_inferred_type_static_explicit_initialized() { 3343 test_field_inferred_type_static_explicit_initialized() {
3280 UnlinkedVariable v = 3344 UnlinkedVariable v =
3281 serializeClassText('class C { static int v = 0; }').fields[0]; 3345 serializeClassText('class C { static int v = 0; }').fields[0];
3282 expect(v.inferredTypeSlot, 0); 3346 expect(v.inferredTypeSlot, 0);
3283 } 3347 }
3284 3348
3285 test_field_inferred_type_static_implicit_initialized() { 3349 test_field_inferred_type_static_implicit_initialized() {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
3363 * Docs 3427 * Docs
3364 */ 3428 */
3365 get f => null;'''; 3429 get f => null;''';
3366 UnlinkedExecutable executable = serializeExecutableText(text); 3430 UnlinkedExecutable executable = serializeExecutableText(text);
3367 expect(executable.documentationComment, isNotNull); 3431 expect(executable.documentationComment, isNotNull);
3368 checkDocumentationComment(executable.documentationComment, text); 3432 checkDocumentationComment(executable.documentationComment, text);
3369 } 3433 }
3370 3434
3371 test_getter_inferred_type_nonstatic_explicit_return() { 3435 test_getter_inferred_type_nonstatic_explicit_return() {
3372 UnlinkedExecutable f = serializeClassText( 3436 UnlinkedExecutable f = serializeClassText(
3373 'class C extends D { num get f => null; }' 3437 'class C extends D { num get f => null; }'
3374 ' abstract class D { int get f; }', 3438 ' abstract class D { int get f; }',
3375 className: 'C', 3439 className: 'C',
3376 allowErrors: true).executables[0]; 3440 allowErrors: true)
3441 .executables[0];
3377 expect(f.inferredReturnTypeSlot, 0); 3442 expect(f.inferredReturnTypeSlot, 0);
3378 } 3443 }
3379 3444
3380 test_getter_inferred_type_nonstatic_implicit_return() { 3445 test_getter_inferred_type_nonstatic_implicit_return() {
3381 UnlinkedExecutable f = serializeClassText( 3446 UnlinkedExecutable f = serializeClassText(
3382 'class C extends D { get f => null; } abstract class D { int get f; }', 3447 'class C extends D { get f => null; } abstract class D { int get f; }',
3383 className: 'C').executables[0]; 3448 className: 'C')
3449 .executables[0];
3384 checkInferredTypeSlot( 3450 checkInferredTypeSlot(
3385 f.inferredReturnTypeSlot, 'dart:core', 'dart:core', 'int'); 3451 f.inferredReturnTypeSlot, 'dart:core', 'dart:core', 'int');
3386 } 3452 }
3387 3453
3388 test_getter_inferred_type_static_implicit_return() { 3454 test_getter_inferred_type_static_implicit_return() {
3389 UnlinkedExecutable f = serializeClassText( 3455 UnlinkedExecutable f = serializeClassText(
3390 'class C extends D { static get f => null; }' 3456 'class C extends D { static get f => null; }'
3391 ' class D { static int get f => null; }', 3457 ' class D { static int get f => null; }',
3392 className: 'C').executables[0]; 3458 className: 'C')
3459 .executables[0];
3393 expect(f.inferredReturnTypeSlot, 0); 3460 expect(f.inferredReturnTypeSlot, 0);
3394 } 3461 }
3395 3462
3396 test_implicit_dependencies_follow_other_dependencies() { 3463 test_implicit_dependencies_follow_other_dependencies() {
3397 if (skipFullyLinkedData) { 3464 if (skipFullyLinkedData) {
3398 return; 3465 return;
3399 } 3466 }
3400 addNamedSource('/a.dart', 'import "b.dart"; class C {} D f() => null;'); 3467 addNamedSource('/a.dart', 'import "b.dart"; class C {} D f() => null;');
3401 addNamedSource('/b.dart', 'class D {}'); 3468 addNamedSource('/b.dart', 'class D {}');
3402 serializeLibraryText('import "a.dart"; final x = f(); C y;'); 3469 serializeLibraryText('import "a.dart"; final x = f(); C y;');
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
3772 */ 3839 */
3773 f() {} 3840 f() {}
3774 }'''; 3841 }''';
3775 UnlinkedExecutable executable = serializeClassText(text).executables[0]; 3842 UnlinkedExecutable executable = serializeClassText(text).executables[0];
3776 expect(executable.documentationComment, isNotNull); 3843 expect(executable.documentationComment, isNotNull);
3777 checkDocumentationComment(executable.documentationComment, text); 3844 checkDocumentationComment(executable.documentationComment, text);
3778 } 3845 }
3779 3846
3780 test_method_inferred_type_nonstatic_explicit_param() { 3847 test_method_inferred_type_nonstatic_explicit_param() {
3781 UnlinkedExecutable f = serializeClassText( 3848 UnlinkedExecutable f = serializeClassText(
3782 'class C extends D { void f(num value) {} }' 3849 'class C extends D { void f(num value) {} }'
3783 ' abstract class D { void f(int value); }', 3850 ' abstract class D { void f(int value); }',
3784 className: 'C').executables[0]; 3851 className: 'C')
3852 .executables[0];
3785 expect(f.parameters[0].inferredTypeSlot, 0); 3853 expect(f.parameters[0].inferredTypeSlot, 0);
3786 } 3854 }
3787 3855
3788 test_method_inferred_type_nonstatic_explicit_return() { 3856 test_method_inferred_type_nonstatic_explicit_return() {
3789 UnlinkedExecutable f = serializeClassText( 3857 UnlinkedExecutable f = serializeClassText(
3790 'class C extends D { num f() => null; } abstract class D { int f(); }', 3858 'class C extends D { num f() => null; } abstract class D { int f(); }',
3791 className: 'C', 3859 className: 'C',
3792 allowErrors: true).executables[0]; 3860 allowErrors: true)
3861 .executables[0];
3793 expect(f.inferredReturnTypeSlot, 0); 3862 expect(f.inferredReturnTypeSlot, 0);
3794 } 3863 }
3795 3864
3796 test_method_inferred_type_nonstatic_implicit_param() { 3865 test_method_inferred_type_nonstatic_implicit_param() {
3797 UnlinkedExecutable f = serializeClassText( 3866 UnlinkedExecutable f = serializeClassText(
3798 'class C extends D { void f(value) {} }' 3867 'class C extends D { void f(value) {} }'
3799 ' abstract class D { void f(int value); }', 3868 ' abstract class D { void f(int value); }',
3800 className: 'C').executables[0]; 3869 className: 'C')
3870 .executables[0];
3801 checkInferredTypeSlot( 3871 checkInferredTypeSlot(
3802 f.parameters[0].inferredTypeSlot, 'dart:core', 'dart:core', 'int'); 3872 f.parameters[0].inferredTypeSlot, 'dart:core', 'dart:core', 'int');
3803 } 3873 }
3804 3874
3805 test_method_inferred_type_nonstatic_implicit_return() { 3875 test_method_inferred_type_nonstatic_implicit_return() {
3806 UnlinkedExecutable f = serializeClassText( 3876 UnlinkedExecutable f = serializeClassText(
3807 'class C extends D { f() => null; } abstract class D { int f(); }', 3877 'class C extends D { f() => null; } abstract class D { int f(); }',
3808 className: 'C').executables[0]; 3878 className: 'C')
3879 .executables[0];
3809 checkInferredTypeSlot( 3880 checkInferredTypeSlot(
3810 f.inferredReturnTypeSlot, 'dart:core', 'dart:core', 'int'); 3881 f.inferredReturnTypeSlot, 'dart:core', 'dart:core', 'int');
3811 } 3882 }
3812 3883
3813 test_method_inferred_type_static_implicit_param() { 3884 test_method_inferred_type_static_implicit_param() {
3814 UnlinkedExecutable f = serializeClassText( 3885 UnlinkedExecutable f = serializeClassText(
3815 'class C extends D { static void f(value) {} }' 3886 'class C extends D { static void f(value) {} }'
3816 ' class D { static void f(int value) {} }', 3887 ' class D { static void f(int value) {} }',
3817 className: 'C').executables[0]; 3888 className: 'C')
3889 .executables[0];
3818 expect(f.parameters[0].inferredTypeSlot, 0); 3890 expect(f.parameters[0].inferredTypeSlot, 0);
3819 } 3891 }
3820 3892
3821 test_method_inferred_type_static_implicit_return() { 3893 test_method_inferred_type_static_implicit_return() {
3822 UnlinkedExecutable f = serializeClassText( 3894 UnlinkedExecutable f = serializeClassText(
3823 'class C extends D { static f() => null; }' 3895 'class C extends D { static f() => null; }'
3824 ' class D { static int f() => null; }', 3896 ' class D { static int f() => null; }',
3825 className: 'C').executables[0]; 3897 className: 'C')
3898 .executables[0];
3826 expect(f.inferredReturnTypeSlot, 0); 3899 expect(f.inferredReturnTypeSlot, 0);
3827 } 3900 }
3828 3901
3829 test_part_declaration() { 3902 test_part_declaration() {
3830 addNamedSource('/a.dart', 'part of my.lib;'); 3903 addNamedSource('/a.dart', 'part of my.lib;');
3831 String text = 'library my.lib; part "a.dart"; // <-part'; 3904 String text = 'library my.lib; part "a.dart"; // <-part';
3832 serializeLibraryText(text); 3905 serializeLibraryText(text);
3833 expect(unlinkedUnits[0].publicNamespace.parts, hasLength(1)); 3906 expect(unlinkedUnits[0].publicNamespace.parts, hasLength(1));
3834 expect(unlinkedUnits[0].publicNamespace.parts[0], 'a.dart'); 3907 expect(unlinkedUnits[0].publicNamespace.parts[0], 'a.dart');
3835 expect(unlinkedUnits[0].parts, hasLength(1)); 3908 expect(unlinkedUnits[0].parts, hasLength(1));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
3868 * Docs 3941 * Docs
3869 */ 3942 */
3870 void set f(value) {}'''; 3943 void set f(value) {}''';
3871 UnlinkedExecutable executable = serializeExecutableText(text, 'f='); 3944 UnlinkedExecutable executable = serializeExecutableText(text, 'f=');
3872 expect(executable.documentationComment, isNotNull); 3945 expect(executable.documentationComment, isNotNull);
3873 checkDocumentationComment(executable.documentationComment, text); 3946 checkDocumentationComment(executable.documentationComment, text);
3874 } 3947 }
3875 3948
3876 test_setter_inferred_type_nonstatic_explicit_param() { 3949 test_setter_inferred_type_nonstatic_explicit_param() {
3877 UnlinkedExecutable f = serializeClassText( 3950 UnlinkedExecutable f = serializeClassText(
3878 'class C extends D { void set f(num value) {} }' 3951 'class C extends D { void set f(num value) {} }'
3879 ' abstract class D { void set f(int value); }', 3952 ' abstract class D { void set f(int value); }',
3880 className: 'C').executables[0]; 3953 className: 'C')
3954 .executables[0];
3881 expect(f.parameters[0].inferredTypeSlot, 0); 3955 expect(f.parameters[0].inferredTypeSlot, 0);
3882 } 3956 }
3883 3957
3884 test_setter_inferred_type_nonstatic_explicit_return() { 3958 test_setter_inferred_type_nonstatic_explicit_return() {
3885 UnlinkedExecutable f = 3959 UnlinkedExecutable f =
3886 serializeClassText('class C { void set f(int value) {} }').executables[ 3960 serializeClassText('class C { void set f(int value) {} }').executables[
3887 0]; 3961 0];
3888 expect(f.inferredReturnTypeSlot, 0); 3962 expect(f.inferredReturnTypeSlot, 0);
3889 } 3963 }
3890 3964
3891 test_setter_inferred_type_nonstatic_implicit_param() { 3965 test_setter_inferred_type_nonstatic_implicit_param() {
3892 UnlinkedExecutable f = serializeClassText( 3966 UnlinkedExecutable f = serializeClassText(
3893 'class C extends D { void set f(value) {} }' 3967 'class C extends D { void set f(value) {} }'
3894 ' abstract class D { void set f(int value); }', 3968 ' abstract class D { void set f(int value); }',
3895 className: 'C').executables[0]; 3969 className: 'C')
3970 .executables[0];
3896 checkInferredTypeSlot( 3971 checkInferredTypeSlot(
3897 f.parameters[0].inferredTypeSlot, 'dart:core', 'dart:core', 'int'); 3972 f.parameters[0].inferredTypeSlot, 'dart:core', 'dart:core', 'int');
3898 } 3973 }
3899 3974
3900 test_setter_inferred_type_nonstatic_implicit_return() { 3975 test_setter_inferred_type_nonstatic_implicit_return() {
3901 UnlinkedExecutable f = 3976 UnlinkedExecutable f =
3902 serializeClassText('class C { set f(int value) {} }').executables[0]; 3977 serializeClassText('class C { set f(int value) {} }').executables[0];
3903 checkInferredTypeSlot(f.inferredReturnTypeSlot, null, null, 'void'); 3978 checkInferredTypeSlot(f.inferredReturnTypeSlot, null, null, 'void');
3904 } 3979 }
3905 3980
3906 test_setter_inferred_type_static_implicit_param() { 3981 test_setter_inferred_type_static_implicit_param() {
3907 UnlinkedExecutable f = serializeClassText( 3982 UnlinkedExecutable f = serializeClassText(
3908 'class C extends D { static void set f(value) {} }' 3983 'class C extends D { static void set f(value) {} }'
3909 ' class D { static void set f(int value) {} }', 3984 ' class D { static void set f(int value) {} }',
3910 className: 'C').executables[0]; 3985 className: 'C')
3986 .executables[0];
3911 expect(f.parameters[0].inferredTypeSlot, 0); 3987 expect(f.parameters[0].inferredTypeSlot, 0);
3912 } 3988 }
3913 3989
3914 test_setter_inferred_type_static_implicit_return() { 3990 test_setter_inferred_type_static_implicit_return() {
3915 UnlinkedExecutable f = 3991 UnlinkedExecutable f =
3916 serializeClassText('class C { static set f(int value) {} }') 3992 serializeClassText('class C { static set f(int value) {} }')
3917 .executables[0]; 3993 .executables[0];
3918 expect(f.inferredReturnTypeSlot, 0); 3994 expect(f.inferredReturnTypeSlot, 0);
3919 } 3995 }
3920 3996
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
4583 expect(constExpr.operations, operators); 4659 expect(constExpr.operations, operators);
4584 expect(constExpr.ints, ints); 4660 expect(constExpr.ints, ints);
4585 expect(constExpr.doubles, doubles); 4661 expect(constExpr.doubles, doubles);
4586 expect(constExpr.strings, strings); 4662 expect(constExpr.strings, strings);
4587 expect(constExpr.references, hasLength(referenceValidators.length)); 4663 expect(constExpr.references, hasLength(referenceValidators.length));
4588 for (int i = 0; i < referenceValidators.length; i++) { 4664 for (int i = 0; i < referenceValidators.length; i++) {
4589 referenceValidators[i](constExpr.references[i]); 4665 referenceValidators[i](constExpr.references[i]);
4590 } 4666 }
4591 } 4667 }
4592 } 4668 }
4669
4670 /**
4671 * Description of expectations for a prelinked prefix reference.
4672 */
4673 class _PrefixExpectation {
4674 final ReferenceKind kind;
4675 final String name;
4676 final bool inLibraryDefiningUnit;
4677 final int numTypeParameters;
4678
4679 _PrefixExpectation(this.kind, this.name,
4680 {this.inLibraryDefiningUnit: false, this.numTypeParameters: 0});
4681 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/summarize_elements.dart ('k') | pkg/analyzer/tool/summary/idl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698