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

Side by Side Diff: pkg/analysis_server/lib/src/domains/analysis/occurrences.dart

Issue 1338153002: Merge occurrences. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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
« no previous file with comments | « no previous file | pkg/analysis_server/test/plugin/set_analysis_domain_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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
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 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/plugin/set_analysis_domain_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698