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

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

Issue 921833002: Issue 22381. Fix for navigating to constructor from redirecting factory constructor. (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/lib/src/edit/edit_domain.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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 computer._addRegion_nodeStart_nodeEnd( 143 computer._addRegion_nodeStart_nodeEnd(
144 firstNode, 144 firstNode,
145 lastNode, 145 lastNode,
146 node.element); 146 node.element);
147 } 147 }
148 } 148 }
149 super.visitConstructorDeclaration(node); 149 super.visitConstructorDeclaration(node);
150 } 150 }
151 151
152 @override 152 @override
153 visitConstructorName(ConstructorName node) {
154 AstNode parent = node.parent;
155 if (parent is InstanceCreationExpression &&
156 parent.constructorName == node) {
157 _addConstructorName(parent, node);
158 } else if (parent is ConstructorDeclaration &&
159 parent.redirectedConstructor == node) {
160 _addConstructorName(node, node);
161 }
162 }
163
164 @override
153 visitExportDirective(ExportDirective node) { 165 visitExportDirective(ExportDirective node) {
154 ExportElement exportElement = node.element; 166 ExportElement exportElement = node.element;
155 if (exportElement != null) { 167 if (exportElement != null) {
156 Element element = exportElement.exportedLibrary; 168 Element element = exportElement.exportedLibrary;
157 computer._addRegion_tokenStart_nodeEnd(node.keyword, node.uri, element); 169 computer._addRegion_tokenStart_nodeEnd(node.keyword, node.uri, element);
158 } 170 }
159 super.visitExportDirective(node); 171 super.visitExportDirective(node);
160 } 172 }
161 173
162 @override 174 @override
163 visitImportDirective(ImportDirective node) { 175 visitImportDirective(ImportDirective node) {
164 ImportElement importElement = node.element; 176 ImportElement importElement = node.element;
165 if (importElement != null) { 177 if (importElement != null) {
166 Element element = importElement.importedLibrary; 178 Element element = importElement.importedLibrary;
167 computer._addRegion_tokenStart_nodeEnd(node.keyword, node.uri, element); 179 computer._addRegion_tokenStart_nodeEnd(node.keyword, node.uri, element);
168 } 180 }
169 super.visitImportDirective(node); 181 super.visitImportDirective(node);
170 } 182 }
171 183
172 @override 184 @override
173 visitIndexExpression(IndexExpression node) { 185 visitIndexExpression(IndexExpression node) {
174 super.visitIndexExpression(node); 186 super.visitIndexExpression(node);
175 computer._addRegionForToken(node.rightBracket, node.bestElement); 187 computer._addRegionForToken(node.rightBracket, node.bestElement);
176 } 188 }
177 189
178 @override 190 @override
179 visitInstanceCreationExpression(InstanceCreationExpression node) {
180 Element element = node.staticElement;
181 ConstructorName constructorName = node.constructorName;
182 if (element != null && constructorName != null) {
183 // if a synthetic constructor, navigate to the class
184 if (element.isSynthetic) {
185 ClassElement classElement = element.enclosingElement;
186 element = classElement;
187 }
188 // add regions
189 TypeName typeName = constructorName.type;
190 TypeArgumentList typeArguments = typeName.typeArguments;
191 if (typeArguments == null) {
192 computer._addRegion_nodeStart_nodeEnd(node, constructorName, element);
193 } else {
194 computer._addRegion_nodeStart_nodeEnd(node, typeName.name, element);
195 // <TypeA, TypeB>
196 typeArguments.accept(this);
197 // optional ".name"
198 if (constructorName.period != null) {
199 computer._addRegion_tokenStart_nodeEnd(
200 constructorName.period,
201 constructorName,
202 element);
203 }
204 }
205 }
206 _safelyVisit(node.argumentList);
207 }
208
209 @override
210 visitPartDirective(PartDirective node) { 191 visitPartDirective(PartDirective node) {
211 computer._addRegion_tokenStart_nodeEnd( 192 computer._addRegion_tokenStart_nodeEnd(
212 node.keyword, 193 node.keyword,
213 node.uri, 194 node.uri,
214 node.element); 195 node.element);
215 super.visitPartDirective(node); 196 super.visitPartDirective(node);
216 } 197 }
217 198
218 @override 199 @override
219 visitPartOfDirective(PartOfDirective node) { 200 visitPartOfDirective(PartOfDirective node) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 SimpleIdentifier name = node.constructorName; 236 SimpleIdentifier name = node.constructorName;
256 if (name != null) { 237 if (name != null) {
257 computer._addRegion_nodeStart_nodeEnd(node, name, element); 238 computer._addRegion_nodeStart_nodeEnd(node, name, element);
258 } else { 239 } else {
259 computer._addRegionForToken(node.keyword, element); 240 computer._addRegionForToken(node.keyword, element);
260 } 241 }
261 // process arguments 242 // process arguments
262 _safelyVisit(node.argumentList); 243 _safelyVisit(node.argumentList);
263 } 244 }
264 245
246 void _addConstructorName(AstNode parent, ConstructorName node) {
247 Element element = node.staticElement;
248 if (element == null) {
249 return;
250 }
251 // if a synthetic constructor, navigate to the class
252 if (element.isSynthetic) {
253 ClassElement classElement = element.enclosingElement;
254 element = classElement;
Brian Wilkerson 2015/02/12 17:56:19 Why the temporary variable? Why not just: elemen
255 }
256 // add regions
257 TypeName typeName = node.type;
258 TypeArgumentList typeArguments = typeName.typeArguments;
259 if (typeArguments == null) {
260 computer._addRegion_nodeStart_nodeEnd(parent, node, element);
261 } else {
262 computer._addRegion_nodeStart_nodeEnd(parent, typeName.name, element);
263 // <TypeA, TypeB>
264 typeArguments.accept(this);
265 // optional ".name"
266 if (node.period != null) {
267 computer._addRegion_tokenStart_nodeEnd(node.period, node, element);
268 }
269 }
270 }
271
265 void _safelyVisit(AstNode node) { 272 void _safelyVisit(AstNode node) {
266 if (node != null) { 273 if (node != null) {
267 node.accept(this); 274 node.accept(this);
268 } 275 }
269 } 276 }
270 } 277 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/edit/edit_domain.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698