| OLD | NEW |
| 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 dart2js.world.class_set; | 5 library dart2js.world.class_set; |
| 6 | 6 |
| 7 import 'dart:collection' show | 7 import 'dart:collection' show |
| 8 IterableBase; | 8 IterableBase; |
| 9 import '../common.dart'; | 9 import '../common.dart'; |
| 10 import '../elements/elements.dart' show | 10 import '../elements/elements.dart' show |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 /// class, visitation is stopped immediately and the function returns `true`. | 214 /// class, visitation is stopped immediately and the function returns `true`. |
| 215 /// | 215 /// |
| 216 /// [predicate] is applied to subclasses if their instantiation properties | 216 /// [predicate] is applied to subclasses if their instantiation properties |
| 217 /// intersect with their corresponding [Instantiation] values in [mask]. If | 217 /// intersect with their corresponding [Instantiation] values in [mask]. If |
| 218 /// [strict] is `true`, [predicate] is _not_ called on [cls] itself. | 218 /// [strict] is `true`, [predicate] is _not_ called on [cls] itself. |
| 219 bool anySubclass( | 219 bool anySubclass( |
| 220 bool predicate(ClassElement cls), | 220 bool predicate(ClassElement cls), |
| 221 EnumSet<Instantiation> mask, | 221 EnumSet<Instantiation> mask, |
| 222 {bool strict: false}) { | 222 {bool strict: false}) { |
| 223 | 223 |
| 224 ForEach wrapper(ClassElement cls) { | 224 IterationStep wrapper(ClassElement cls) { |
| 225 return predicate(cls) ? ForEach.STOP : ForEach.CONTINUE; | 225 return predicate(cls) ? IterationStep.STOP : IterationStep.CONTINUE; |
| 226 } | 226 } |
| 227 return forEachSubclass(wrapper, mask, strict: strict) == ForEach.STOP; | 227 return forEachSubclass(wrapper, mask, strict: strict) == IterationStep.STOP; |
| 228 } | 228 } |
| 229 | 229 |
| 230 /// Applies [f] to each subclass of [cls] matching the criteria specified by | 230 /// Applies [f] to each subclass of [cls] matching the criteria specified by |
| 231 /// [mask] and [strict]. | 231 /// [mask] and [strict]. |
| 232 /// | 232 /// |
| 233 /// [f] is a applied to subclasses if their instantiation properties intersect | 233 /// [f] is a applied to subclasses if their instantiation properties intersect |
| 234 /// with their corresponding [Instantiation] values in [mask]. If [strict] is | 234 /// with their corresponding [Instantiation] values in [mask]. If [strict] is |
| 235 /// `true`, [f] is _not_ called on [cls] itself. | 235 /// `true`, [f] is _not_ called on [cls] itself. |
| 236 /// | 236 /// |
| 237 /// The visitation of subclasses can be cut short by the return value of [f]. | 237 /// The visitation of subclasses can be cut short by the return value of [f]. |
| 238 /// If [ForEach.STOP] is returned, no further classes are visited and the | 238 /// If [ForEach.STOP] is returned, no further classes are visited and the |
| 239 /// function stops immediately. If [ForEach.SKIP_SUBCLASSES] is returned, the | 239 /// function stops immediately. If [ForEach.SKIP_SUBCLASSES] is returned, the |
| 240 /// subclasses of the last visited class are skipped, but visitation | 240 /// subclasses of the last visited class are skipped, but visitation |
| 241 /// continues. The return value of the function is either [ForEach.STOP], if | 241 /// continues. The return value of the function is either [ForEach.STOP], if |
| 242 /// visitation was stopped, or [ForEach.CONTINUE] if visitation continued to | 242 /// visitation was stopped, or [ForEach.CONTINUE] if visitation continued to |
| 243 /// the end. | 243 /// the end. |
| 244 ForEach forEachSubclass( | 244 IterationStep forEachSubclass( |
| 245 ForEachFunction f, | 245 ForEachFunction f, |
| 246 EnumSet<Instantiation> mask, | 246 EnumSet<Instantiation> mask, |
| 247 {bool strict: false}) { | 247 {bool strict: false}) { |
| 248 ForEach forEach; | 248 IterationStep nextStep; |
| 249 if (!strict && mask.intersects(_mask)) { | 249 if (!strict && mask.intersects(_mask)) { |
| 250 forEach = f(cls); | 250 nextStep = f(cls); |
| 251 } | 251 } |
| 252 // Interpret `forEach == null` as `forEach == ForEach.CONTINUE`. | 252 // Interpret `forEach == null` as `forEach == ForEach.CONTINUE`. |
| 253 forEach ??= ForEach.CONTINUE; | 253 nextStep ??= IterationStep.CONTINUE; |
| 254 | 254 |
| 255 if (forEach == ForEach.CONTINUE) { | 255 if (nextStep == IterationStep.CONTINUE) { |
| 256 if (mask.contains(Instantiation.UNINSTANTIATED) || isInstantiated) { | 256 if (mask.contains(Instantiation.UNINSTANTIATED) || isInstantiated) { |
| 257 for (ClassHierarchyNode subclass in _directSubclasses) { | 257 for (ClassHierarchyNode subclass in _directSubclasses) { |
| 258 ForEach subForEach = subclass.forEachSubclass(f, mask); | 258 IterationStep subForEach = subclass.forEachSubclass(f, mask); |
| 259 if (subForEach == ForEach.STOP) { | 259 if (subForEach == IterationStep.STOP) { |
| 260 return subForEach; | 260 return subForEach; |
| 261 } | 261 } |
| 262 } | 262 } |
| 263 } | 263 } |
| 264 } | 264 } |
| 265 if (forEach == ForEach.STOP) { | 265 if (nextStep == IterationStep.STOP) { |
| 266 return forEach; | 266 return nextStep; |
| 267 } | 267 } |
| 268 return ForEach.CONTINUE; | 268 return IterationStep.CONTINUE; |
| 269 } | 269 } |
| 270 | 270 |
| 271 /// Returns the most specific subclass of [cls] (including [cls]) that is | 271 /// Returns the most specific subclass of [cls] (including [cls]) that is |
| 272 /// directly instantiated or a superclass of all directly instantiated | 272 /// directly instantiated or a superclass of all directly instantiated |
| 273 /// subclasses. If [cls] is not instantiated, `null` is returned. | 273 /// subclasses. If [cls] is not instantiated, `null` is returned. |
| 274 ClassElement getLubOfInstantiatedSubclasses() { | 274 ClassElement getLubOfInstantiatedSubclasses() { |
| 275 if (!isInstantiated) return null; | 275 if (!isInstantiated) return null; |
| 276 if (_leastUpperInstantiatedSubclass == null) { | 276 if (_leastUpperInstantiatedSubclass == null) { |
| 277 _leastUpperInstantiatedSubclass = | 277 _leastUpperInstantiatedSubclass = |
| 278 _computeLeastUpperInstantiatedSubclass(); | 278 _computeLeastUpperInstantiatedSubclass(); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 /// if we expand the subclass subtrees: | 418 /// if we expand the subclass subtrees: |
| 419 /// | 419 /// |
| 420 /// A -> [C, D, F] | 420 /// A -> [C, D, F] |
| 421 /// | | | 421 /// | | |
| 422 /// B E | 422 /// B E |
| 423 /// | 423 /// |
| 424 class ClassSet { | 424 class ClassSet { |
| 425 final ClassHierarchyNode node; | 425 final ClassHierarchyNode node; |
| 426 ClassElement _leastUpperInstantiatedSubtype; | 426 ClassElement _leastUpperInstantiatedSubtype; |
| 427 | 427 |
| 428 List<ClassHierarchyNode> _directSubtypes; | 428 /// A list of the class hierarchy nodes for the subtypes that declare a |
| 429 /// subtype relationship to [cls] either directly or indirectly. |
| 430 /// |
| 431 /// For instance |
| 432 /// |
| 433 /// class A {} |
| 434 /// class B extends A {} |
| 435 /// class C implements B {} |
| 436 /// class D implements A {} |
| 437 /// class E extends D {} |
| 438 /// |
| 439 /// The class hierarchy nodes for classes `C` and `D` are in [_subtypes]. `C` |
| 440 /// because it implements `A` through `B` and `D` because it implements `A` |
| 441 /// directly. `E` also implements `A` through its extension of `D` and it is |
| 442 /// therefore included through the class hierarchy node for `D`. |
| 443 /// |
| 444 List<ClassHierarchyNode> _subtypes; |
| 429 | 445 |
| 430 ClassSet(this.node); | 446 ClassSet(this.node); |
| 431 | 447 |
| 432 ClassElement get cls => node.cls; | 448 ClassElement get cls => node.cls; |
| 433 | 449 |
| 434 /// Returns the number of directly instantiated subtypes of [cls]. | 450 /// Returns the number of directly instantiated subtypes of [cls]. |
| 435 int get instantiatedSubtypeCount { | 451 int get instantiatedSubtypeCount { |
| 436 int count = node.instantiatedSubclassCount; | 452 int count = node.instantiatedSubclassCount; |
| 437 if (_directSubtypes != null) { | 453 if (_subtypes != null) { |
| 438 for (ClassHierarchyNode subtypeNode in _directSubtypes) { | 454 for (ClassHierarchyNode subtypeNode in _subtypes) { |
| 439 if (subtypeNode.isDirectlyInstantiated) { | 455 if (subtypeNode.isDirectlyInstantiated) { |
| 440 count++; | 456 count++; |
| 441 } | 457 } |
| 442 count += subtypeNode.instantiatedSubclassCount; | 458 count += subtypeNode.instantiatedSubclassCount; |
| 443 } | 459 } |
| 444 } | 460 } |
| 445 return count; | 461 return count; |
| 446 } | 462 } |
| 447 | 463 |
| 448 /// Returns `true` if all instantiated subtypes of [cls] are subclasses of | 464 /// Returns `true` if all instantiated subtypes of [cls] are subclasses of |
| 449 /// [cls]. | 465 /// [cls]. |
| 450 bool get hasOnlyInstantiatedSubclasses { | 466 bool get hasOnlyInstantiatedSubclasses { |
| 451 if (_directSubtypes != null) { | 467 if (_subtypes != null) { |
| 452 for (ClassHierarchyNode subtypeNode in _directSubtypes) { | 468 for (ClassHierarchyNode subtypeNode in _subtypes) { |
| 453 if (subtypeNode.isInstantiated) { | 469 if (subtypeNode.isInstantiated) { |
| 454 return false; | 470 return false; |
| 455 } | 471 } |
| 456 } | 472 } |
| 457 } | 473 } |
| 458 return true; | 474 return true; |
| 459 } | 475 } |
| 460 | 476 |
| 461 /// Returns an [Iterable] of the subclasses of [cls] possibly including [cls]. | 477 /// Returns an [Iterable] of the subclasses of [cls] possibly including [cls]. |
| 462 /// | 478 /// |
| (...skipping 25 matching lines...) Expand all Loading... |
| 488 } | 504 } |
| 489 | 505 |
| 490 /// Returns an [Iterable] of the subtypes of [cls] possibly including [cls]. | 506 /// Returns an [Iterable] of the subtypes of [cls] possibly including [cls]. |
| 491 /// | 507 /// |
| 492 /// Subtypes are included if their instantiation properties intersect with | 508 /// Subtypes are included if their instantiation properties intersect with |
| 493 /// their corresponding [Instantiation] values in [mask]. If [strict] is | 509 /// their corresponding [Instantiation] values in [mask]. If [strict] is |
| 494 /// `true`, [cls] itself is _not_ returned. | 510 /// `true`, [cls] itself is _not_ returned. |
| 495 Iterable<ClassElement> subtypesByMask( | 511 Iterable<ClassElement> subtypesByMask( |
| 496 EnumSet<Instantiation> mask, | 512 EnumSet<Instantiation> mask, |
| 497 {bool strict: false}) { | 513 {bool strict: false}) { |
| 498 if (_directSubtypes == null) { | 514 if (_subtypes == null) { |
| 499 return node.subclassesByMask( | 515 return node.subclassesByMask( |
| 500 mask, | 516 mask, |
| 501 strict: strict); | 517 strict: strict); |
| 502 } | 518 } |
| 503 | 519 |
| 504 return new SubtypesIterable.SubtypesIterator(this, | 520 return new SubtypesIterable.SubtypesIterator(this, |
| 505 mask, | 521 mask, |
| 506 includeRoot: !strict); | 522 includeRoot: !strict); |
| 507 } | 523 } |
| 508 | 524 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 527 /// with their corresponding [Instantiation] values in [mask]. If [strict] is | 543 /// with their corresponding [Instantiation] values in [mask]. If [strict] is |
| 528 /// `true`, [f] is _not_ called on [cls] itself. | 544 /// `true`, [f] is _not_ called on [cls] itself. |
| 529 /// | 545 /// |
| 530 /// The visitation of subclasses can be cut short by the return value of [f]. | 546 /// The visitation of subclasses can be cut short by the return value of [f]. |
| 531 /// If [ForEach.STOP] is returned, no further classes are visited and the | 547 /// If [ForEach.STOP] is returned, no further classes are visited and the |
| 532 /// function stops immediately. If [ForEach.SKIP_SUBCLASSES] is returned, the | 548 /// function stops immediately. If [ForEach.SKIP_SUBCLASSES] is returned, the |
| 533 /// subclasses of the last visited class are skipped, but visitation | 549 /// subclasses of the last visited class are skipped, but visitation |
| 534 /// continues. The return value of the function is either [ForEach.STOP], if | 550 /// continues. The return value of the function is either [ForEach.STOP], if |
| 535 /// visitation was stopped, or [ForEach.CONTINUE] if visitation continued to | 551 /// visitation was stopped, or [ForEach.CONTINUE] if visitation continued to |
| 536 /// the end. | 552 /// the end. |
| 537 ForEach forEachSubclass( | 553 IterationStep forEachSubclass( |
| 538 ForEachFunction f, | 554 ForEachFunction f, |
| 539 EnumSet<Instantiation> mask, | 555 EnumSet<Instantiation> mask, |
| 540 {bool strict: false}) { | 556 {bool strict: false}) { |
| 541 return node.forEachSubclass(f, mask, strict: strict); | 557 return node.forEachSubclass(f, mask, strict: strict); |
| 542 } | 558 } |
| 543 | 559 |
| 544 /// Applies [predicate] to each subtype of [cls] matching the criteria | 560 /// Applies [predicate] to each subtype of [cls] matching the criteria |
| 545 /// specified by [mask] and [strict]. If [predicate] returns `true` on a | 561 /// specified by [mask] and [strict]. If [predicate] returns `true` on a |
| 546 /// class, visitation is stopped immediately and the function returns `true`. | 562 /// class, visitation is stopped immediately and the function returns `true`. |
| 547 /// | 563 /// |
| 548 /// [predicate] is applied to subtypes if their instantiation properties | 564 /// [predicate] is applied to subtypes if their instantiation properties |
| 549 /// intersect with their corresponding [Instantiation] values in [mask]. If | 565 /// intersect with their corresponding [Instantiation] values in [mask]. If |
| 550 /// [strict] is `true`, [predicate] is _not_ called on [cls] itself. | 566 /// [strict] is `true`, [predicate] is _not_ called on [cls] itself. |
| 551 bool anySubtype( | 567 bool anySubtype( |
| 552 bool predicate(ClassElement cls), | 568 bool predicate(ClassElement cls), |
| 553 EnumSet<Instantiation> mask, | 569 EnumSet<Instantiation> mask, |
| 554 {bool strict: false}) { | 570 {bool strict: false}) { |
| 555 | 571 |
| 556 ForEach wrapper(ClassElement cls) { | 572 IterationStep wrapper(ClassElement cls) { |
| 557 return predicate(cls) ? ForEach.STOP : ForEach.CONTINUE; | 573 return predicate(cls) ? IterationStep.STOP : IterationStep.CONTINUE; |
| 558 } | 574 } |
| 559 return forEachSubtype(wrapper, mask, strict: strict) == ForEach.STOP; | 575 return forEachSubtype(wrapper, mask, strict: strict) == IterationStep.STOP; |
| 560 } | 576 } |
| 561 | 577 |
| 562 /// Applies [f] to each subtype of [cls] matching the criteria specified by | 578 /// Applies [f] to each subtype of [cls] matching the criteria specified by |
| 563 /// [mask] and [strict]. | 579 /// [mask] and [strict]. |
| 564 /// | 580 /// |
| 565 /// [f] is a applied to subtypes if their instantiation properties intersect | 581 /// [f] is a applied to subtypes if their instantiation properties intersect |
| 566 /// with their corresponding [Instantiation] values in [mask]. If [strict] is | 582 /// with their corresponding [Instantiation] values in [mask]. If [strict] is |
| 567 /// `true`, [f] is _not_ called on [cls] itself. | 583 /// `true`, [f] is _not_ called on [cls] itself. |
| 568 /// | 584 /// |
| 569 /// The visitation of subtypes can be cut short by the return value of [f]. | 585 /// The visitation of subtypes can be cut short by the return value of [f]. |
| 570 /// If [ForEach.STOP] is returned, no further classes are visited and the | 586 /// If [ForEach.STOP] is returned, no further classes are visited and the |
| 571 /// function stops immediately. If [ForEach.SKIP_SUBCLASSES] is returned, the | 587 /// function stops immediately. If [ForEach.SKIP_SUBCLASSES] is returned, the |
| 572 /// subclasses of the last visited class are skipped, but visitation | 588 /// subclasses of the last visited class are skipped, but visitation |
| 573 /// continues. The return value of the function is either [ForEach.STOP], if | 589 /// continues. The return value of the function is either [ForEach.STOP], if |
| 574 /// visitation was stopped, or [ForEach.CONTINUE] if visitation continued to | 590 /// visitation was stopped, or [ForEach.CONTINUE] if visitation continued to |
| 575 /// the end. | 591 /// the end. |
| 576 ForEach forEachSubtype( | 592 IterationStep forEachSubtype( |
| 577 ForEachFunction f, | 593 ForEachFunction f, |
| 578 EnumSet<Instantiation> mask, | 594 EnumSet<Instantiation> mask, |
| 579 {bool strict: false}) { | 595 {bool strict: false}) { |
| 580 ForEach forEach = node.forEachSubclass(f, mask, strict: strict); | 596 IterationStep nextStep = |
| 581 forEach ??= ForEach.CONTINUE; | 597 node.forEachSubclass(f, mask, strict: strict) ?? IterationStep.CONTINUE; |
| 582 if (forEach == ForEach.CONTINUE && _directSubtypes != null) { | 598 if (nextStep == IterationStep.CONTINUE && _subtypes != null) { |
| 583 for (ClassHierarchyNode subclass in _directSubtypes) { | 599 for (ClassHierarchyNode subclass in _subtypes) { |
| 584 ForEach subForEach = subclass.forEachSubclass(f, mask); | 600 IterationStep subForEach = subclass.forEachSubclass(f, mask); |
| 585 if (subForEach == ForEach.STOP) { | 601 if (subForEach == IterationStep.STOP) { |
| 586 return subForEach; | 602 return subForEach; |
| 587 } | 603 } |
| 588 } | 604 } |
| 589 } | 605 } |
| 590 assert(forEach != ForEach.SKIP_SUBCLASSES); | 606 assert(nextStep != IterationStep.SKIP_SUBCLASSES); |
| 591 return forEach; | 607 return nextStep; |
| 592 } | 608 } |
| 593 | 609 |
| 594 /// Adds [subtype] as a subtype of [cls]. | 610 /// Adds [subtype] as a subtype of [cls]. |
| 595 void addSubtype(ClassHierarchyNode subtype) { | 611 void addSubtype(ClassHierarchyNode subtype) { |
| 596 if (node.contains(subtype.cls)) { | 612 if (node.contains(subtype.cls)) { |
| 597 return; | 613 return; |
| 598 } | 614 } |
| 599 if (_directSubtypes == null) { | 615 if (_subtypes == null) { |
| 600 _directSubtypes = <ClassHierarchyNode>[subtype]; | 616 _subtypes = <ClassHierarchyNode>[subtype]; |
| 601 } else { | 617 } else { |
| 602 int hierarchyDepth = subtype.cls.hierarchyDepth; | 618 int hierarchyDepth = subtype.cls.hierarchyDepth; |
| 603 List<ClassHierarchyNode> newSubtypes = <ClassHierarchyNode>[]; | 619 List<ClassHierarchyNode> newSubtypes = <ClassHierarchyNode>[]; |
| 604 bool added = false; | 620 bool added = false; |
| 605 for (ClassHierarchyNode otherSubtype in _directSubtypes) { | 621 for (ClassHierarchyNode otherSubtype in _subtypes) { |
| 606 int otherHierarchyDepth = otherSubtype.cls.hierarchyDepth; | 622 int otherHierarchyDepth = otherSubtype.cls.hierarchyDepth; |
| 607 if (hierarchyDepth == otherHierarchyDepth) { | 623 if (hierarchyDepth == otherHierarchyDepth) { |
| 608 if (subtype == otherSubtype) { | 624 if (subtype == otherSubtype) { |
| 609 return; | 625 return; |
| 610 } else { | 626 } else { |
| 611 // [otherSubtype] is unrelated to [subtype]. | 627 // [otherSubtype] is unrelated to [subtype]. |
| 612 newSubtypes.add(otherSubtype); | 628 newSubtypes.add(otherSubtype); |
| 613 } | 629 } |
| 614 } else if (hierarchyDepth > otherSubtype.cls.hierarchyDepth) { | 630 } else if (hierarchyDepth > otherSubtype.cls.hierarchyDepth) { |
| 615 // [otherSubtype] could be a superclass of [subtype]. | 631 // [otherSubtype] could be a superclass of [subtype]. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 630 if (subtype.contains(otherSubtype.cls)) { | 646 if (subtype.contains(otherSubtype.cls)) { |
| 631 // Replace [otherSubtype]. | 647 // Replace [otherSubtype]. |
| 632 } else { | 648 } else { |
| 633 newSubtypes.add(otherSubtype); | 649 newSubtypes.add(otherSubtype); |
| 634 } | 650 } |
| 635 } | 651 } |
| 636 } | 652 } |
| 637 if (!added) { | 653 if (!added) { |
| 638 newSubtypes.add(subtype); | 654 newSubtypes.add(subtype); |
| 639 } | 655 } |
| 640 _directSubtypes = newSubtypes; | 656 _subtypes = newSubtypes; |
| 641 } | 657 } |
| 642 } | 658 } |
| 643 | 659 |
| 644 /// Returns the most specific subtype of [cls] (including [cls]) that is | 660 /// Returns the most specific subtype of [cls] (including [cls]) that is |
| 645 /// directly instantiated or a superclass of all directly instantiated | 661 /// directly instantiated or a superclass of all directly instantiated |
| 646 /// subtypes. If no subtypes of [cls] are instantiated, `null` is returned. | 662 /// subtypes. If no subtypes of [cls] are instantiated, `null` is returned. |
| 647 ClassElement getLubOfInstantiatedSubtypes() { | 663 ClassElement getLubOfInstantiatedSubtypes() { |
| 648 if (_leastUpperInstantiatedSubtype == null) { | 664 if (_leastUpperInstantiatedSubtype == null) { |
| 649 _leastUpperInstantiatedSubtype = _computeLeastUpperInstantiatedSubtype(); | 665 _leastUpperInstantiatedSubtype = _computeLeastUpperInstantiatedSubtype(); |
| 650 } | 666 } |
| 651 return _leastUpperInstantiatedSubtype; | 667 return _leastUpperInstantiatedSubtype; |
| 652 } | 668 } |
| 653 | 669 |
| 654 ClassElement _computeLeastUpperInstantiatedSubtype() { | 670 ClassElement _computeLeastUpperInstantiatedSubtype() { |
| 655 if (node.isDirectlyInstantiated) { | 671 if (node.isDirectlyInstantiated) { |
| 656 return cls; | 672 return cls; |
| 657 } | 673 } |
| 658 if (_directSubtypes == null) { | 674 if (_subtypes == null) { |
| 659 return node.getLubOfInstantiatedSubclasses(); | 675 return node.getLubOfInstantiatedSubclasses(); |
| 660 } | 676 } |
| 661 ClassHierarchyNode subtype; | 677 ClassHierarchyNode subtype; |
| 662 if (node.isInstantiated) { | 678 if (node.isInstantiated) { |
| 663 subtype = node; | 679 subtype = node; |
| 664 } | 680 } |
| 665 for (ClassHierarchyNode subnode in _directSubtypes) { | 681 for (ClassHierarchyNode subnode in _subtypes) { |
| 666 if (subnode.isInstantiated) { | 682 if (subnode.isInstantiated) { |
| 667 if (subtype == null) { | 683 if (subtype == null) { |
| 668 subtype = subnode; | 684 subtype = subnode; |
| 669 } else { | 685 } else { |
| 670 return cls; | 686 return cls; |
| 671 } | 687 } |
| 672 } | 688 } |
| 673 } | 689 } |
| 674 if (subtype != null) { | 690 if (subtype != null) { |
| 675 return subtype.getLubOfInstantiatedSubclasses(); | 691 return subtype.getLubOfInstantiatedSubclasses(); |
| 676 } | 692 } |
| 677 return null; | 693 return null; |
| 678 } | 694 } |
| 679 | 695 |
| 680 String toString() { | 696 String toString() { |
| 681 StringBuffer sb = new StringBuffer(); | 697 StringBuffer sb = new StringBuffer(); |
| 682 sb.write('[\n'); | 698 sb.write('[\n'); |
| 683 node.printOn(sb, ' '); | 699 node.printOn(sb, ' '); |
| 684 sb.write('\n'); | 700 sb.write('\n'); |
| 685 if (_directSubtypes != null) { | 701 if (_subtypes != null) { |
| 686 for (ClassHierarchyNode node in _directSubtypes) { | 702 for (ClassHierarchyNode node in _subtypes) { |
| 687 node.printOn(sb, ' '); | 703 node.printOn(sb, ' '); |
| 688 sb.write('\n'); | 704 sb.write('\n'); |
| 689 } | 705 } |
| 690 } | 706 } |
| 691 sb.write(']'); | 707 sb.write(']'); |
| 692 return sb.toString(); | 708 return sb.toString(); |
| 693 } | 709 } |
| 694 } | 710 } |
| 695 | 711 |
| 696 /// Iterable for subclasses of a [ClassHierarchyNode]. | 712 /// Iterable for subclasses of a [ClassHierarchyNode]. |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 // Initial state. Iterate through subclasses. | 850 // Initial state. Iterate through subclasses. |
| 835 elements = iterable.subtypeSet.node.subclassesByMask( | 851 elements = iterable.subtypeSet.node.subclassesByMask( |
| 836 mask, | 852 mask, |
| 837 strict: !includeRoot).iterator; | 853 strict: !includeRoot).iterator; |
| 838 } | 854 } |
| 839 if (elements != null && elements.moveNext()) { | 855 if (elements != null && elements.moveNext()) { |
| 840 return true; | 856 return true; |
| 841 } | 857 } |
| 842 if (hierarchyNodes == null) { | 858 if (hierarchyNodes == null) { |
| 843 // Start iterating through subtypes. | 859 // Start iterating through subtypes. |
| 844 hierarchyNodes = iterable.subtypeSet._directSubtypes.iterator; | 860 hierarchyNodes = iterable.subtypeSet._subtypes.iterator; |
| 845 } | 861 } |
| 846 while (hierarchyNodes.moveNext()) { | 862 while (hierarchyNodes.moveNext()) { |
| 847 elements = hierarchyNodes.current.subclassesByMask(mask).iterator; | 863 elements = hierarchyNodes.current.subclassesByMask(mask).iterator; |
| 848 if (elements.moveNext()) { | 864 if (elements.moveNext()) { |
| 849 return true; | 865 return true; |
| 850 } | 866 } |
| 851 } | 867 } |
| 852 return false; | 868 return false; |
| 853 } | 869 } |
| 854 } | 870 } |
| 855 | 871 |
| 856 /// Enum values returned from the [ForEachFunction] provided to the `forEachX` | 872 /// Enum values returned from the [ForEachFunction] provided to the `forEachX` |
| 857 /// functions of [ClassHierarchyNode] and [ClassSet]. The value is used to | 873 /// functions of [ClassHierarchyNode] and [ClassSet]. The value is used to |
| 858 /// control the continued iteration. | 874 /// control the continued iteration. |
| 859 enum ForEach { | 875 enum IterationStep { |
| 860 /// Iteration continues. | 876 /// Iteration continues. |
| 861 CONTINUE, | 877 CONTINUE, |
| 862 /// Iteration stops immediately. | 878 /// Iteration stops immediately. |
| 863 STOP, | 879 STOP, |
| 864 /// Iteration skips the subclasses of the current class. | 880 /// Iteration skips the subclasses of the current class. |
| 865 SKIP_SUBCLASSES, | 881 SKIP_SUBCLASSES, |
| 866 } | 882 } |
| 867 | 883 |
| 868 /// Visiting function used for the `forEachX` functions of [ClassHierarchyNode] | 884 /// Visiting function used for the `forEachX` functions of [ClassHierarchyNode] |
| 869 /// and [ClassSet]. The return value controls the continued iteration. If `null` | 885 /// and [ClassSet]. The return value controls the continued iteration. If `null` |
| 870 /// is returned, iteration continues to the end. | 886 /// is returned, iteration continues to the end. |
| 871 typedef ForEach ForEachFunction(ClassElement cls); | 887 typedef IterationStep ForEachFunction(ClassElement cls); |
| OLD | NEW |