OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 computer.navigation; | 5 library computer.navigation; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
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/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
11 import 'package:analyzer/src/generated/element.dart'; | 11 import 'package:analyzer/src/generated/element.dart'; |
12 import 'package:analyzer/src/generated/scanner.dart'; | 12 import 'package:analyzer/src/generated/scanner.dart'; |
13 import 'package:analyzer/src/generated/source.dart'; | 13 import 'package:analyzer/src/generated/source.dart'; |
14 | 14 |
15 /** | 15 /** |
16 * A computer for navigation regions in a Dart [CompilationUnit]. | 16 * A computer for navigation regions in a Dart [CompilationUnit]. |
17 */ | 17 */ |
18 class DartUnitNavigationComputer { | 18 class DartUnitNavigationComputer { |
19 final CompilationUnit _unit; | |
20 | |
21 final List<String> files = <String>[]; | 19 final List<String> files = <String>[]; |
22 final Map<String, int> fileMap = new HashMap<String, int>(); | 20 final Map<String, int> fileMap = new HashMap<String, int>(); |
23 final List<protocol.NavigationTarget> targets = <protocol.NavigationTarget>[]; | 21 final List<protocol.NavigationTarget> targets = <protocol.NavigationTarget>[]; |
24 final Map<Element, int> targetMap = new HashMap<Element, int>(); | 22 final Map<Element, int> targetMap = new HashMap<Element, int>(); |
25 final List<protocol.NavigationRegion> regions = <protocol.NavigationRegion>[]; | 23 final List<protocol.NavigationRegion> regions = <protocol.NavigationRegion>[]; |
26 | 24 |
27 DartUnitNavigationComputer(this._unit); | |
28 | |
29 /** | 25 /** |
30 * Computes [regions], [targets] and [files]. | 26 * Computes [regions], [targets] and [files]. |
31 */ | 27 */ |
32 void compute() { | 28 void compute(AstNode node) { |
33 _unit.accept(new _DartUnitNavigationComputerVisitor(this)); | 29 node.accept(new _DartUnitNavigationComputerVisitor(this)); |
34 } | 30 } |
35 | 31 |
36 int _addFile(String file) { | 32 int _addFile(String file) { |
37 int index = fileMap[file]; | 33 int index = fileMap[file]; |
38 if (index == null) { | 34 if (index == null) { |
39 index = files.length; | 35 index = files.length; |
40 files.add(file); | 36 files.add(file); |
41 fileMap[file] = index; | 37 fileMap[file] = index; |
42 } | 38 } |
43 return index; | 39 return index; |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 } | 266 } |
271 } | 267 } |
272 } | 268 } |
273 | 269 |
274 void _safelyVisit(AstNode node) { | 270 void _safelyVisit(AstNode node) { |
275 if (node != null) { | 271 if (node != null) { |
276 node.accept(this); | 272 node.accept(this); |
277 } | 273 } |
278 } | 274 } |
279 } | 275 } |
OLD | NEW |