| 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/constants.dart'; | 9 import 'package:analysis_server/src/constants.dart'; |
| 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 import 'element.dart' as computer; | 15 import 'element.dart' as computer; |
| 16 | 16 |
| 17 | 17 |
| 18 /** | 18 /** |
| 19 * A computer for navigation regions in a Dart [CompilationUnit]. | 19 * A computer for navigation regions in a Dart [CompilationUnit]. |
| 20 */ | 20 */ |
| 21 class DartUnitNavigationComputer { | 21 class DartUnitNavigationComputer { |
| 22 final CompilationUnit _unit; | 22 final CompilationUnit _unit; |
| 23 | 23 |
| 24 final List<HashMap<String, Object>> _regions = <HashMap<String, Object>>[]; | 24 final List<Map<String, Object>> _regions = <HashMap<String, Object>>[]; |
| 25 | 25 |
| 26 DartUnitNavigationComputer(this._unit); | 26 DartUnitNavigationComputer(this._unit); |
| 27 | 27 |
| 28 /** | 28 /** |
| 29 * Returns the computed navigation regions, not `null`. | 29 * Returns the computed navigation regions, not `null`. |
| 30 */ | 30 */ |
| 31 List<HashMap<String, Object>> compute() { | 31 List<Map<String, Object>> compute() { |
| 32 _unit.accept(new _DartUnitNavigationComputerVisitor(this)); | 32 _unit.accept(new _DartUnitNavigationComputerVisitor(this)); |
| 33 return new List.from(_regions); | 33 return new List.from(_regions); |
| 34 } | 34 } |
| 35 | 35 |
| 36 void _addRegion(int offset, int length, Element element) { | 36 void _addRegion(int offset, int length, Element element) { |
| 37 HashMap<String, Object> target = _createTarget(element); | 37 Map<String, Object> target = _createTarget(element); |
| 38 if (target == null) { | 38 if (target == null) { |
| 39 return; | 39 return; |
| 40 } | 40 } |
| 41 _regions.add({ | 41 _regions.add({ |
| 42 OFFSET: offset, | 42 OFFSET: offset, |
| 43 LENGTH: length, | 43 LENGTH: length, |
| 44 TARGETS: [target] | 44 TARGETS: [target] |
| 45 }); | 45 }); |
| 46 } | 46 } |
| 47 | 47 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 71 | 71 |
| 72 void _addRegion_tokenStart_nodeEnd(Token a, AstNode b, Element element) { | 72 void _addRegion_tokenStart_nodeEnd(Token a, AstNode b, Element element) { |
| 73 int offset = a.offset; | 73 int offset = a.offset; |
| 74 int length = b.end - offset; | 74 int length = b.end - offset; |
| 75 _addRegion(offset, length, element); | 75 _addRegion(offset, length, element); |
| 76 } | 76 } |
| 77 | 77 |
| 78 /** | 78 /** |
| 79 * Returns the JSON for the given [Element], maybe `null` if `null` was given. | 79 * Returns the JSON for the given [Element], maybe `null` if `null` was given. |
| 80 */ | 80 */ |
| 81 HashMap<String, Object> _createTarget(Element element) { | 81 Map<String, Object> _createTarget(Element element) { |
| 82 if (element == null) { | 82 if (element == null) { |
| 83 return null; | 83 return null; |
| 84 } | 84 } |
| 85 if (element is FieldFormalParameterElement) { | 85 if (element is FieldFormalParameterElement) { |
| 86 element = (element as FieldFormalParameterElement).field; | 86 element = (element as FieldFormalParameterElement).field; |
| 87 } | 87 } |
| 88 // prepare Source | 88 // prepare Source |
| 89 Source source = element.source; | 89 Source source = element.source; |
| 90 if (source == null) { | 90 if (source == null) { |
| 91 return null; | 91 return null; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 | 207 |
| 208 @override | 208 @override |
| 209 visitSimpleIdentifier(SimpleIdentifier node) { | 209 visitSimpleIdentifier(SimpleIdentifier node) { |
| 210 if (node.parent is ConstructorDeclaration) { | 210 if (node.parent is ConstructorDeclaration) { |
| 211 } else { | 211 } else { |
| 212 computer._addRegionForNode(node, node.bestElement); | 212 computer._addRegionForNode(node, node.bestElement); |
| 213 } | 213 } |
| 214 return super.visitSimpleIdentifier(node); | 214 return super.visitSimpleIdentifier(node); |
| 215 } | 215 } |
| 216 } | 216 } |
| OLD | NEW |