| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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:collection'; | 5 import 'dart:collection'; |
| 6 | 6 |
| 7 import 'package:analysis_server/plugin/protocol/protocol.dart' | 7 import 'package:analysis_server/plugin/protocol/protocol.dart' |
| 8 hide AnalysisErrorFixes; | 8 hide AnalysisErrorFixes; |
| 9 import 'package:analyzer_plugin/protocol/generated_protocol.dart' as plugin; | 9 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin; |
| 10 import 'package:meta/meta.dart'; | 10 import 'package:meta/meta.dart'; |
| 11 | 11 |
| 12 /** | 12 /** |
| 13 * An object used to merge partial lists of results that were contributed by | 13 * An object used to merge partial lists of results that were contributed by |
| 14 * plugins. | 14 * plugins. |
| 15 * | 15 * |
| 16 * All of the methods in this class assume that the contributions from the | 16 * All of the methods in this class assume that the contributions from the |
| 17 * analysis server are the first partial result in the list of partial results | 17 * analysis server are the first partial result in the list of partial results |
| 18 * to be merged. | 18 * to be merged. |
| 19 */ | 19 */ |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 return outline; | 504 return outline; |
| 505 } | 505 } |
| 506 | 506 |
| 507 for (int i = 0; i < mergedOutlines.length; i++) { | 507 for (int i = 0; i < mergedOutlines.length; i++) { |
| 508 mergedOutlines[i] = traverse(mergedOutlines[i]); | 508 mergedOutlines[i] = traverse(mergedOutlines[i]); |
| 509 } | 509 } |
| 510 return mergedOutlines; | 510 return mergedOutlines; |
| 511 } | 511 } |
| 512 | 512 |
| 513 /** | 513 /** |
| 514 * Return a list of source changes composed by merging the lists of source |
| 515 * changes in the [partialResultList]. |
| 516 * |
| 517 * The resulting list will contain all of the source changes from all of the |
| 518 * plugins. If two or more plugins contribute the same source change the |
| 519 * resulting list will contain duplications. |
| 520 */ |
| 521 List<plugin.PrioritizedSourceChange> mergePrioritizedSourceChanges( |
| 522 List<List<plugin.PrioritizedSourceChange>> partialResultList) { |
| 523 int count = partialResultList.length; |
| 524 if (count == 0) { |
| 525 return <plugin.PrioritizedSourceChange>[]; |
| 526 } else if (count == 1) { |
| 527 return partialResultList[0]; |
| 528 } |
| 529 List<plugin.PrioritizedSourceChange> mergedChanges = |
| 530 <plugin.PrioritizedSourceChange>[]; |
| 531 for (List<plugin.PrioritizedSourceChange> partialResults |
| 532 in partialResultList) { |
| 533 mergedChanges.addAll(partialResults); |
| 534 } |
| 535 mergedChanges.sort((first, second) => first.priority - second.priority); |
| 536 return mergedChanges; |
| 537 } |
| 538 |
| 539 /** |
| 514 * Return a refactoring feedback composed by merging the refactoring feedbacks | 540 * Return a refactoring feedback composed by merging the refactoring feedbacks |
| 515 * in the [partialResultList]. | 541 * in the [partialResultList]. |
| 516 * | 542 * |
| 517 * The content of the resulting feedback depends on the kind of feedbacks | 543 * The content of the resulting feedback depends on the kind of feedbacks |
| 518 * being merged. | 544 * being merged. |
| 519 * | 545 * |
| 520 * Throw an exception if the refactoring feedbacks are of an unhandled type. | 546 * Throw an exception if the refactoring feedbacks are of an unhandled type. |
| 521 * | 547 * |
| 522 * The feedbacks in the [partialResultList] are expected to all be of the same | 548 * The feedbacks in the [partialResultList] are expected to all be of the same |
| 523 * type. If that expectation is violated, and exception might be thrown. | 549 * type. If that expectation is violated, and exception might be thrown. |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 } | 783 } |
| 758 | 784 |
| 759 /** | 785 /** |
| 760 * Return a list of source changes composed by merging the lists of source | 786 * Return a list of source changes composed by merging the lists of source |
| 761 * changes in the [partialResultList]. | 787 * changes in the [partialResultList]. |
| 762 * | 788 * |
| 763 * The resulting list will contain all of the source changes from all of the | 789 * The resulting list will contain all of the source changes from all of the |
| 764 * plugins. If two or more plugins contribute the same source change the | 790 * plugins. If two or more plugins contribute the same source change the |
| 765 * resulting list will contain duplications. | 791 * resulting list will contain duplications. |
| 766 */ | 792 */ |
| 767 List<plugin.PrioritizedSourceChange> mergePrioritizedSourceChanges( | |
| 768 List<List<plugin.PrioritizedSourceChange>> partialResultList) { | |
| 769 int count = partialResultList.length; | |
| 770 if (count == 0) { | |
| 771 return <plugin.PrioritizedSourceChange>[]; | |
| 772 } else if (count == 1) { | |
| 773 return partialResultList[0]; | |
| 774 } | |
| 775 List<plugin.PrioritizedSourceChange> mergedChanges = <plugin.PrioritizedSour
ceChange>[]; | |
| 776 for (List<plugin.PrioritizedSourceChange> partialResults in partialResultLis
t) { | |
| 777 mergedChanges.addAll(partialResults); | |
| 778 } | |
| 779 mergedChanges.sort((first, second) => first.priority - second.priority); | |
| 780 return mergedChanges; | |
| 781 } | |
| 782 | |
| 783 /** | |
| 784 * Return a list of source changes composed by merging the lists of source | |
| 785 * changes in the [partialResultList]. | |
| 786 * | |
| 787 * The resulting list will contain all of the source changes from all of the | |
| 788 * plugins. If two or more plugins contribute the same source change the | |
| 789 * resulting list will contain duplications. | |
| 790 */ | |
| 791 List<SourceChange> mergeSourceChanges( | 793 List<SourceChange> mergeSourceChanges( |
| 792 List<List<SourceChange>> partialResultList) { | 794 List<List<SourceChange>> partialResultList) { |
| 793 int count = partialResultList.length; | 795 int count = partialResultList.length; |
| 794 if (count == 0) { | 796 if (count == 0) { |
| 795 return <SourceChange>[]; | 797 return <SourceChange>[]; |
| 796 } else if (count == 1) { | 798 } else if (count == 1) { |
| 797 return partialResultList[0]; | 799 return partialResultList[0]; |
| 798 } | 800 } |
| 799 List<SourceChange> mergedChanges = <SourceChange>[]; | 801 List<SourceChange> mergedChanges = <SourceChange>[]; |
| 800 for (List<SourceChange> partialResults in partialResultList) { | 802 for (List<SourceChange> partialResults in partialResultList) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 816 if (leftEnd < rightStart || leftStart > rightEnd) { | 818 if (leftEnd < rightStart || leftStart > rightEnd) { |
| 817 return false; | 819 return false; |
| 818 } | 820 } |
| 819 if (!allowNesting) { | 821 if (!allowNesting) { |
| 820 return true; | 822 return true; |
| 821 } | 823 } |
| 822 return !((leftStart <= rightStart && rightEnd <= leftEnd) || | 824 return !((leftStart <= rightStart && rightEnd <= leftEnd) || |
| 823 (rightStart <= leftStart && leftEnd <= rightEnd)); | 825 (rightStart <= leftStart && leftEnd <= rightEnd)); |
| 824 } | 826 } |
| 825 } | 827 } |
| OLD | NEW |