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 'package:analysis_server/src/protocol2.dart' as protocol; |
7 import 'package:analysis_server/src/constants.dart'; | 8 import 'package:analysis_server/src/constants.dart'; |
8 import 'package:analyzer/src/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
9 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
10 import 'package:analyzer/src/generated/scanner.dart'; | 11 import 'package:analyzer/src/generated/scanner.dart'; |
11 | 12 |
12 import 'element.dart' as computer; | |
13 | |
14 | 13 |
15 /** | 14 /** |
16 * A computer for navigation regions in a Dart [CompilationUnit]. | 15 * A computer for navigation regions in a Dart [CompilationUnit]. |
17 */ | 16 */ |
18 class DartUnitNavigationComputer { | 17 class DartUnitNavigationComputer { |
19 final CompilationUnit _unit; | 18 final CompilationUnit _unit; |
20 | 19 |
21 final List<Map<String, Object>> _regions = <Map<String, Object>>[]; | 20 final List<Map<String, Object>> _regions = <Map<String, Object>>[]; |
22 | 21 |
23 DartUnitNavigationComputer(this._unit); | 22 DartUnitNavigationComputer(this._unit); |
24 | 23 |
25 /** | 24 /** |
26 * Returns the computed navigation regions, not `null`. | 25 * Returns the computed navigation regions, not `null`. |
27 */ | 26 */ |
28 List<Map<String, Object>> compute() { | 27 List<Map<String, Object>> compute() { |
29 _unit.accept(new _DartUnitNavigationComputerVisitor(this)); | 28 _unit.accept(new _DartUnitNavigationComputerVisitor(this)); |
30 return new List.from(_regions); | 29 return new List.from(_regions); |
31 } | 30 } |
32 | 31 |
33 void _addRegion(int offset, int length, Element element) { | 32 void _addRegion(int offset, int length, Element element) { |
34 if (element == null || element == DynamicElementImpl.instance) { | 33 if (element == null || element == DynamicElementImpl.instance) { |
35 return; | 34 return; |
36 } | 35 } |
37 if (element is FieldFormalParameterElement) { | 36 if (element is FieldFormalParameterElement) { |
38 element = (element as FieldFormalParameterElement).field; | 37 element = (element as FieldFormalParameterElement).field; |
39 } | 38 } |
40 var elementJson = new computer.Element.fromEngine(element).toJson(); | 39 var elementJson = new protocol.Element.fromEngine(element).toJson(); |
41 _regions.add({ | 40 _regions.add({ |
42 OFFSET: offset, | 41 OFFSET: offset, |
43 LENGTH: length, | 42 LENGTH: length, |
44 TARGETS: [elementJson] | 43 TARGETS: [elementJson] |
45 }); | 44 }); |
46 } | 45 } |
47 | 46 |
48 void _addRegionForNode(AstNode node, Element element) { | 47 void _addRegionForNode(AstNode node, Element element) { |
49 int offset = node.offset; | 48 int offset = node.offset; |
50 int length = node.length; | 49 int length = node.length; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 | 180 |
182 @override | 181 @override |
183 visitSimpleIdentifier(SimpleIdentifier node) { | 182 visitSimpleIdentifier(SimpleIdentifier node) { |
184 if (node.parent is ConstructorDeclaration) { | 183 if (node.parent is ConstructorDeclaration) { |
185 } else { | 184 } else { |
186 computer._addRegionForNode(node, node.bestElement); | 185 computer._addRegionForNode(node, node.bestElement); |
187 } | 186 } |
188 return super.visitSimpleIdentifier(node); | 187 return super.visitSimpleIdentifier(node); |
189 } | 188 } |
190 } | 189 } |
OLD | NEW |