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

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

Issue 3001413002: Remove uses of the old plugin model from the analysis server (Closed)
Patch Set: Created 3 years, 4 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
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 import 'package:analysis_server/plugin/analysis/occurrences/occurrences_core.dar t'; 5 import 'package:analysis_server/plugin/analysis/occurrences/occurrences_core.dar t';
6 import 'package:analysis_server/src/analysis_server.dart';
7 import 'package:analysis_server/src/protocol_server.dart' as protocol; 6 import 'package:analysis_server/src/protocol_server.dart' as protocol;
8 import 'package:analyzer/exception/exception.dart';
9 import 'package:analyzer/src/generated/engine.dart'
10 show AnalysisContext, AnalysisEngine;
11 import 'package:analyzer/src/generated/source.dart' show Source;
12
13 /**
14 * Compute all known occurrences for the given [source].
15 */
16 OccurrencesCollectorImpl computeOccurrences(
17 AnalysisServer server, AnalysisContext context, Source source) {
18 OccurrencesCollectorImpl collector = new OccurrencesCollectorImpl();
19 List<OccurrencesContributor> contributors =
20 server.serverPlugin.occurrencesContributors;
21 for (OccurrencesContributor contributor in contributors) {
22 try {
23 contributor.computeOccurrences(collector, context, source);
24 } catch (exception, stackTrace) {
25 AnalysisEngine.instance.logger.logError(
26 'Exception from occurrences contributor: ${contributor.runtimeType}',
27 new CaughtException(exception, stackTrace));
28 }
29 }
30 return collector;
31 }
32 7
33 /** 8 /**
34 * A concrete implementation of [OccurrencesCollector]. 9 * A concrete implementation of [OccurrencesCollector].
35 */ 10 */
36 class OccurrencesCollectorImpl implements OccurrencesCollector { 11 class OccurrencesCollectorImpl implements OccurrencesCollector {
37 Map<protocol.Element, protocol.Occurrences> elementOccurrences = 12 Map<protocol.Element, protocol.Occurrences> elementOccurrences =
38 <protocol.Element, protocol.Occurrences>{}; 13 <protocol.Element, protocol.Occurrences>{};
39 14
40 List<protocol.Occurrences> get allOccurrences { 15 List<protocol.Occurrences> get allOccurrences {
41 return elementOccurrences.values.toList(); 16 return elementOccurrences.values.toList();
42 } 17 }
43 18
44 @override 19 @override
45 void addOccurrences(protocol.Occurrences current) { 20 void addOccurrences(protocol.Occurrences current) {
46 protocol.Element element = current.element; 21 protocol.Element element = current.element;
47 protocol.Occurrences existing = elementOccurrences[element]; 22 protocol.Occurrences existing = elementOccurrences[element];
48 if (existing != null) { 23 if (existing != null) {
49 List<int> offsets = _merge(existing.offsets, current.offsets); 24 List<int> offsets = _merge(existing.offsets, current.offsets);
50 current = new protocol.Occurrences(element, offsets, existing.length); 25 current = new protocol.Occurrences(element, offsets, existing.length);
51 } 26 }
52 elementOccurrences[element] = current; 27 elementOccurrences[element] = current;
53 } 28 }
54 29
55 static List<int> _merge(List<int> a, List<int> b) { 30 static List<int> _merge(List<int> a, List<int> b) {
56 return <int>[]..addAll(a)..addAll(b); 31 return <int>[]..addAll(a)..addAll(b);
57 } 32 }
58 } 33 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/domains/analysis/navigation.dart ('k') | pkg/analysis_server/lib/src/plugin/server_plugin.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698