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 domains.analysis.occurrences; | 5 library domains.analysis.occurrences; |
6 | 6 |
7 import 'package:analysis_server/analysis/occurrences_core.dart'; | 7 import 'package:analysis_server/analysis/occurrences_core.dart'; |
8 import 'package:analysis_server/src/analysis_server.dart'; | 8 import 'package:analysis_server/src/analysis_server.dart'; |
9 import 'package:analysis_server/src/protocol_server.dart' as protocol; | 9 import 'package:analysis_server/src/protocol_server.dart' as protocol; |
10 import 'package:analyzer/src/generated/engine.dart' | 10 import 'package:analyzer/src/generated/engine.dart' |
(...skipping 18 matching lines...) Expand all Loading... |
29 new CaughtException(exception, stackTrace)); | 29 new CaughtException(exception, stackTrace)); |
30 } | 30 } |
31 } | 31 } |
32 return collector; | 32 return collector; |
33 } | 33 } |
34 | 34 |
35 /** | 35 /** |
36 * A concrete implementation of [OccurrencesCollector]. | 36 * A concrete implementation of [OccurrencesCollector]. |
37 */ | 37 */ |
38 class OccurrencesCollectorImpl implements OccurrencesCollector { | 38 class OccurrencesCollectorImpl implements OccurrencesCollector { |
39 final List<protocol.Occurrences> allOccurrences = <protocol.Occurrences>[]; | 39 Map<protocol.Element, protocol.Occurrences> elementOccurrences = |
| 40 <protocol.Element, protocol.Occurrences>{}; |
| 41 |
| 42 List<protocol.Occurrences> get allOccurrences { |
| 43 return elementOccurrences.values.toList(); |
| 44 } |
40 | 45 |
41 @override | 46 @override |
42 void addOccurrences(protocol.Occurrences occurrences) { | 47 void addOccurrences(protocol.Occurrences current) { |
43 allOccurrences.add(occurrences); | 48 protocol.Element element = current.element; |
| 49 protocol.Occurrences existing = elementOccurrences[element]; |
| 50 if (existing != null) { |
| 51 List<int> offsets = _merge(existing.offsets, current.offsets); |
| 52 current = new protocol.Occurrences(element, offsets, existing.length); |
| 53 } |
| 54 elementOccurrences[element] = current; |
| 55 } |
| 56 |
| 57 static List<int> _merge(List<int> a, List<int> b) { |
| 58 return <int>[]..addAll(a)..addAll(b); |
44 } | 59 } |
45 } | 60 } |
OLD | NEW |