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

Side by Side Diff: pkg/analysis_server/lib/src/computer/computer_navigation.dart

Issue 497393002: Make more use of generated code in analysis server. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 | Annotate | Revision Log
OLDNEW
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/protocol2.dart' as protocol;
8 import 'package:analysis_server/src/constants.dart';
9 import 'package:analyzer/src/generated/ast.dart'; 8 import 'package:analyzer/src/generated/ast.dart';
10 import 'package:analyzer/src/generated/element.dart'; 9 import 'package:analyzer/src/generated/element.dart';
11 import 'package:analyzer/src/generated/scanner.dart'; 10 import 'package:analyzer/src/generated/scanner.dart';
12 11
13 12
14 /** 13 /**
15 * A computer for navigation regions in a Dart [CompilationUnit]. 14 * A computer for navigation regions in a Dart [CompilationUnit].
16 */ 15 */
17 class DartUnitNavigationComputer { 16 class DartUnitNavigationComputer {
18 final CompilationUnit _unit; 17 final CompilationUnit _unit;
19 18
20 final List<Map<String, Object>> _regions = <Map<String, Object>>[]; 19 final List<protocol.NavigationRegion> _regions = <protocol.NavigationRegion>[] ;
21 20
22 DartUnitNavigationComputer(this._unit); 21 DartUnitNavigationComputer(this._unit);
23 22
24 /** 23 /**
25 * Returns the computed navigation regions, not `null`. 24 * Returns the computed navigation regions, not `null`.
26 */ 25 */
27 List<Map<String, Object>> compute() { 26 List<protocol.NavigationRegion> compute() {
28 _unit.accept(new _DartUnitNavigationComputerVisitor(this)); 27 _unit.accept(new _DartUnitNavigationComputerVisitor(this));
29 return new List.from(_regions); 28 return new List.from(_regions);
30 } 29 }
31 30
32 void _addRegion(int offset, int length, Element element) { 31 void _addRegion(int offset, int length, Element element) {
33 if (element == null || element == DynamicElementImpl.instance) { 32 if (element == null || element == DynamicElementImpl.instance) {
34 return; 33 return;
35 } 34 }
36 if (element is FieldFormalParameterElement) { 35 if (element is FieldFormalParameterElement) {
37 element = (element as FieldFormalParameterElement).field; 36 element = (element as FieldFormalParameterElement).field;
38 } 37 }
39 var elementJson = new protocol.Element.fromEngine(element).toJson(); 38 protocol.Element target = new protocol.Element.fromEngine(element);
40 _regions.add({ 39 _regions.add(new protocol.NavigationRegion(offset, length, [target]));
41 OFFSET: offset,
42 LENGTH: length,
43 TARGETS: [elementJson]
44 });
45 } 40 }
46 41
47 void _addRegionForNode(AstNode node, Element element) { 42 void _addRegionForNode(AstNode node, Element element) {
48 int offset = node.offset; 43 int offset = node.offset;
49 int length = node.length; 44 int length = node.length;
50 _addRegion(offset, length, element); 45 _addRegion(offset, length, element);
51 } 46 }
52 47
53 void _addRegionForToken(Token token, Element element) { 48 void _addRegionForToken(Token token, Element element) {
54 int offset = token.offset; 49 int offset = token.offset;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 175
181 @override 176 @override
182 visitSimpleIdentifier(SimpleIdentifier node) { 177 visitSimpleIdentifier(SimpleIdentifier node) {
183 if (node.parent is ConstructorDeclaration) { 178 if (node.parent is ConstructorDeclaration) {
184 } else { 179 } else {
185 computer._addRegionForNode(node, node.bestElement); 180 computer._addRegionForNode(node, node.bestElement);
186 } 181 }
187 return super.visitSimpleIdentifier(node); 182 return super.visitSimpleIdentifier(node);
188 } 183 }
189 } 184 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/computer/computer_hover.dart ('k') | pkg/analysis_server/lib/src/computer/error.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698