Index: pkg/analysis_server/lib/src/domains/analysis/occurrences.dart |
diff --git a/pkg/analysis_server/lib/src/domains/analysis/occurrences.dart b/pkg/analysis_server/lib/src/domains/analysis/occurrences.dart |
index 561693e3bbc2292a3875f1d57a20ea571dca61c4..f0a9a1cda29f7a8e9934fe35a031042788f8c1ec 100644 |
--- a/pkg/analysis_server/lib/src/domains/analysis/occurrences.dart |
+++ b/pkg/analysis_server/lib/src/domains/analysis/occurrences.dart |
@@ -36,10 +36,25 @@ OccurrencesCollectorImpl computeOccurrences( |
* A concrete implementation of [OccurrencesCollector]. |
*/ |
class OccurrencesCollectorImpl implements OccurrencesCollector { |
- final List<protocol.Occurrences> allOccurrences = <protocol.Occurrences>[]; |
+ Map<protocol.Element, protocol.Occurrences> elementOccurrences = |
+ <protocol.Element, protocol.Occurrences>{}; |
+ |
+ List<protocol.Occurrences> get allOccurrences { |
+ return elementOccurrences.values.toList(); |
+ } |
@override |
- void addOccurrences(protocol.Occurrences occurrences) { |
- allOccurrences.add(occurrences); |
+ void addOccurrences(protocol.Occurrences current) { |
+ protocol.Element element = current.element; |
+ protocol.Occurrences existing = elementOccurrences[element]; |
+ if (existing != null) { |
+ List<int> offsets = _merge(existing.offsets, current.offsets); |
+ current = new protocol.Occurrences(element, offsets, existing.length); |
+ } |
+ elementOccurrences[element] = current; |
+ } |
+ |
+ static List<int> _merge(List<int> a, List<int> b) { |
+ return <int>[]..addAll(a)..addAll(b); |
} |
} |