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

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

Issue 882823002: Issue 22143. Navigation from super initializers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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
« no previous file with comments | « no previous file | pkg/analysis_server/test/analysis/notification_navigation_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 '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';
(...skipping 15 matching lines...) Expand all
26 26
27 DartUnitNavigationComputer(this._unit); 27 DartUnitNavigationComputer(this._unit);
28 28
29 /** 29 /**
30 * Computes [regions], [targets] and [files]. 30 * Computes [regions], [targets] and [files].
31 */ 31 */
32 void compute() { 32 void compute() {
33 _unit.accept(new _DartUnitNavigationComputerVisitor(this)); 33 _unit.accept(new _DartUnitNavigationComputerVisitor(this));
34 } 34 }
35 35
36 int _addFile(String file) {
37 int index = fileMap[file];
38 if (index == null) {
39 index = files.length;
40 files.add(file);
41 fileMap[file] = index;
42 }
43 return index;
44 }
45
36 void _addRegion(int offset, int length, Element element) { 46 void _addRegion(int offset, int length, Element element) {
37 if (element is FieldFormalParameterElement) { 47 if (element is FieldFormalParameterElement) {
38 element = (element as FieldFormalParameterElement).field; 48 element = (element as FieldFormalParameterElement).field;
39 } 49 }
40 if (element == null || element == DynamicElementImpl.instance) { 50 if (element == null || element == DynamicElementImpl.instance) {
41 return; 51 return;
42 } 52 }
43 if (element.location == null) { 53 if (element.location == null) {
44 return; 54 return;
45 } 55 }
46 int targetIndex = _addTarget(element); 56 int targetIndex = _addTarget(element);
47 regions.add( 57 regions.add(
48 new protocol.NavigationRegion(offset, length, <int>[targetIndex])); 58 new protocol.NavigationRegion(offset, length, <int>[targetIndex]));
49 } 59 }
50 60
51 int _addTarget(Element element) {
52 int index = targetMap[element];
53 if (index == null) {
54 index = targets.length;
55 protocol.NavigationTarget target =
56 protocol.newNavigationTarget_fromElement(element, _addFile);
57 targets.add(target);
58 targetMap[element] = index;
59 }
60 return index;
61 }
62
63 int _addFile(String file) {
64 int index = fileMap[file];
65 if (index == null) {
66 index = files.length;
67 files.add(file);
68 fileMap[file] = index;
69 }
70 return index;
71 }
72
73 void _addRegion_nodeStart_nodeEnd(AstNode a, AstNode b, Element element) { 61 void _addRegion_nodeStart_nodeEnd(AstNode a, AstNode b, Element element) {
74 int offset = a.offset; 62 int offset = a.offset;
75 int length = b.end - offset; 63 int length = b.end - offset;
76 _addRegion(offset, length, element); 64 _addRegion(offset, length, element);
77 } 65 }
78 66
79 void _addRegion_tokenStart_nodeEnd(Token a, AstNode b, Element element) { 67 void _addRegion_tokenStart_nodeEnd(Token a, AstNode b, Element element) {
80 int offset = a.offset; 68 int offset = a.offset;
81 int length = b.end - offset; 69 int length = b.end - offset;
82 _addRegion(offset, length, element); 70 _addRegion(offset, length, element);
83 } 71 }
84 72
85 void _addRegionForNode(AstNode node, Element element) { 73 void _addRegionForNode(AstNode node, Element element) {
86 int offset = node.offset; 74 int offset = node.offset;
87 int length = node.length; 75 int length = node.length;
88 _addRegion(offset, length, element); 76 _addRegion(offset, length, element);
89 } 77 }
90 78
91 void _addRegionForToken(Token token, Element element) { 79 void _addRegionForToken(Token token, Element element) {
92 int offset = token.offset; 80 int offset = token.offset;
93 int length = token.length; 81 int length = token.length;
94 _addRegion(offset, length, element); 82 _addRegion(offset, length, element);
95 } 83 }
84
85 int _addTarget(Element element) {
86 int index = targetMap[element];
87 if (index == null) {
88 index = targets.length;
89 protocol.NavigationTarget target =
90 protocol.newNavigationTarget_fromElement(element, _addFile);
91 targets.add(target);
92 targetMap[element] = index;
93 }
94 return index;
95 }
96 } 96 }
97 97
98 98
99 class _DartUnitNavigationComputerVisitor extends RecursiveAstVisitor { 99 class _DartUnitNavigationComputerVisitor extends RecursiveAstVisitor {
100 final DartUnitNavigationComputer computer; 100 final DartUnitNavigationComputer computer;
101 101
102 _DartUnitNavigationComputerVisitor(this.computer); 102 _DartUnitNavigationComputerVisitor(this.computer);
103 103
104 @override 104 @override
105 visitAssignmentExpression(AssignmentExpression node) { 105 visitAssignmentExpression(AssignmentExpression node) {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 238
239 @override 239 @override
240 visitSimpleIdentifier(SimpleIdentifier node) { 240 visitSimpleIdentifier(SimpleIdentifier node) {
241 if (node.parent is ConstructorDeclaration) { 241 if (node.parent is ConstructorDeclaration) {
242 return; 242 return;
243 } 243 }
244 Element element = node.bestElement; 244 Element element = node.bestElement;
245 computer._addRegionForNode(node, element); 245 computer._addRegionForNode(node, element);
246 } 246 }
247 247
248 @override
249 visitSuperConstructorInvocation(SuperConstructorInvocation node) {
250 Element element = node.staticElement;
251 if (element != null && element.isSynthetic) {
252 element = element.enclosingElement;
253 }
254 // add region
255 SimpleIdentifier name = node.constructorName;
256 if (name != null) {
257 computer._addRegion_nodeStart_nodeEnd(node, name, element);
258 } else {
259 computer._addRegionForToken(node.keyword, element);
260 }
261 // process arguments
262 _safelyVisit(node.argumentList);
263 }
264
248 void _safelyVisit(AstNode node) { 265 void _safelyVisit(AstNode node) {
249 if (node != null) { 266 if (node != null) {
250 node.accept(this); 267 node.accept(this);
251 } 268 }
252 } 269 }
253 } 270 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/analysis/notification_navigation_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698