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

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

Issue 3002253002: Use the NavigationCollector from analyzer_plugin to avoid duplication (Closed)
Patch Set: Created 3 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'dart:collection';
6
7 import 'package:analysis_server/plugin/analysis/navigation/navigation_core.dart' ;
8 import 'package:analysis_server/src/collections.dart';
9 import 'package:analysis_server/src/protocol_server.dart' as protocol;
10 import 'package:analyzer/src/generated/source.dart' show SourceRange;
11
12 /**
13 * A concrete implementation of [NavigationCollector].
14 */
15 class NavigationCollectorImpl implements NavigationCollector {
16 /**
17 * A list of navigation regions.
18 */
19 final List<protocol.NavigationRegion> regions = <protocol.NavigationRegion>[];
20 final Map<SourceRange, List<int>> regionMap =
21 new HashMap<SourceRange, List<int>>();
22
23 /**
24 * All the unique targets referenced by [regions].
25 */
26 final List<protocol.NavigationTarget> targets = <protocol.NavigationTarget>[];
27 final Map<Pair<protocol.ElementKind, protocol.Location>, int> targetMap =
28 new HashMap<Pair<protocol.ElementKind, protocol.Location>, int>();
29
30 /**
31 * All the unique files referenced by [targets].
32 */
33 final List<String> files = <String>[];
34 final Map<String, int> fileMap = new HashMap<String, int>();
35
36 @override
37 void addRegion(int offset, int length, protocol.ElementKind targetKind,
38 protocol.Location targetLocation) {
39 SourceRange range = new SourceRange(offset, length);
40 // prepare targets
41 List<int> targets = regionMap[range];
42 if (targets == null) {
43 targets = <int>[];
44 regionMap[range] = targets;
45 }
46 // add new target
47 int targetIndex = _addTarget(targetKind, targetLocation);
48 targets.add(targetIndex);
49 }
50
51 void createRegions() {
52 regionMap.forEach((range, targets) {
53 protocol.NavigationRegion region =
54 new protocol.NavigationRegion(range.offset, range.length, targets);
55 regions.add(region);
56 });
57 regions.sort((a, b) {
58 return a.offset - b.offset;
59 });
60 }
61
62 int _addFile(String file) {
63 int index = fileMap[file];
64 if (index == null) {
65 index = files.length;
66 files.add(file);
67 fileMap[file] = index;
68 }
69 return index;
70 }
71
72 int _addTarget(protocol.ElementKind kind, protocol.Location location) {
73 var pair =
74 new Pair<protocol.ElementKind, protocol.Location>(kind, location);
75 int index = targetMap[pair];
76 if (index == null) {
77 String file = location.file;
78 int fileIndex = _addFile(file);
79 index = targets.length;
80 protocol.NavigationTarget target = new protocol.NavigationTarget(
81 kind,
82 fileIndex,
83 location.offset,
84 location.length,
85 location.startLine,
86 location.startColumn);
87 targets.add(target);
88 targetMap[pair] = index;
89 }
90 return index;
91 }
92 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/domain_analysis.dart ('k') | pkg/analysis_server/lib/src/domains/analysis/navigation_dart.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698