Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 domains.analysis.navigation_dart; | 5 library domains.analysis.navigation_dart; |
| 6 | 6 |
| 7 import 'package:analysis_server/plugin/analysis/navigation/navigation_core.dart' ; | 7 import 'package:analysis_server/plugin/analysis/navigation/navigation_core.dart' ; |
| 8 import 'package:analysis_server/src/protocol_server.dart' as protocol; | 8 import 'package:analysis_server/src/protocol_server.dart' as protocol; |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
| 11 import 'package:analyzer/dart/ast/visitor.dart'; | 11 import 'package:analyzer/dart/ast/visitor.dart'; |
| 12 import 'package:analyzer/dart/element/element.dart'; | 12 import 'package:analyzer/dart/element/element.dart'; |
| 13 import 'package:analyzer/dart/element/type.dart'; | |
| 13 import 'package:analyzer/src/dart/ast/utilities.dart'; | 14 import 'package:analyzer/src/dart/ast/utilities.dart'; |
| 14 import 'package:analyzer/src/dart/element/element.dart'; | 15 import 'package:analyzer/src/dart/element/element.dart'; |
| 15 import 'package:analyzer/src/generated/engine.dart'; | 16 import 'package:analyzer/src/generated/engine.dart'; |
| 16 import 'package:analyzer/src/generated/source.dart'; | 17 import 'package:analyzer/src/generated/source.dart'; |
| 17 | 18 |
| 18 NavigationCollector computeDartNavigation(NavigationCollector collector, | 19 NavigationCollector computeDartNavigation(NavigationCollector collector, |
| 19 CompilationUnit unit, int offset, int length) { | 20 CompilationUnit unit, int offset, int length) { |
| 20 _DartNavigationCollector dartCollector = | 21 _DartNavigationCollector dartCollector = |
| 21 new _DartNavigationCollector(collector); | 22 new _DartNavigationCollector(collector); |
| 22 _DartNavigationComputerVisitor visitor = | 23 _DartNavigationComputerVisitor visitor = |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 if (parent is InstanceCreationExpression && | 188 if (parent is InstanceCreationExpression && |
| 188 parent.constructorName == node) { | 189 parent.constructorName == node) { |
| 189 _addConstructorName(parent, node); | 190 _addConstructorName(parent, node); |
| 190 } else if (parent is ConstructorDeclaration && | 191 } else if (parent is ConstructorDeclaration && |
| 191 parent.redirectedConstructor == node) { | 192 parent.redirectedConstructor == node) { |
| 192 _addConstructorName(node, node); | 193 _addConstructorName(node, node); |
| 193 } | 194 } |
| 194 } | 195 } |
| 195 | 196 |
| 196 @override | 197 @override |
| 198 visitDeclaredIdentifier(DeclaredIdentifier node) { | |
| 199 if (node.type == null) { | |
| 200 Token token = node.keyword; | |
| 201 if (token?.keyword == Keyword.VAR) { | |
| 202 DartType inferredType = node.identifier?.bestType; | |
| 203 Element element = inferredType?.element; | |
| 204 if (element != null) { | |
| 205 computer._addRegionForToken(token, element); | |
| 206 } | |
| 207 } | |
| 208 } | |
| 209 super.visitDeclaredIdentifier(node); | |
| 210 } | |
| 211 | |
| 212 @override | |
| 197 visitExportDirective(ExportDirective node) { | 213 visitExportDirective(ExportDirective node) { |
| 198 ExportElement exportElement = node.element; | 214 ExportElement exportElement = node.element; |
| 199 if (exportElement != null) { | 215 if (exportElement != null) { |
| 200 Element libraryElement = exportElement.exportedLibrary; | 216 Element libraryElement = exportElement.exportedLibrary; |
| 201 _addUriDirectiveRegion(node, libraryElement); | 217 _addUriDirectiveRegion(node, libraryElement); |
| 202 } | 218 } |
| 203 super.visitExportDirective(node); | 219 super.visitExportDirective(node); |
| 204 } | 220 } |
| 205 | 221 |
| 206 @override | 222 @override |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 if (element != null && element.isSynthetic) { | 294 if (element != null && element.isSynthetic) { |
| 279 element = element.enclosingElement; | 295 element = element.enclosingElement; |
| 280 } | 296 } |
| 281 // add region | 297 // add region |
| 282 computer._addRegionForToken(node.superKeyword, element); | 298 computer._addRegionForToken(node.superKeyword, element); |
| 283 computer._addRegionForNode(node.constructorName, element); | 299 computer._addRegionForNode(node.constructorName, element); |
| 284 // process arguments | 300 // process arguments |
| 285 node.argumentList?.accept(this); | 301 node.argumentList?.accept(this); |
| 286 } | 302 } |
| 287 | 303 |
| 304 @override | |
| 305 visitVariableDeclarationList(VariableDeclarationList node) { | |
| 306 /** | |
| 307 * Return the element for the type inferred for each of the variables in the | |
| 308 * given list of [variables], or `null` if not all variable have the same | |
| 309 * inferred type. | |
| 310 */ | |
| 311 Element getCommonElement(List<VariableDeclaration> variables) { | |
| 312 Element firstElement = variables[0].name?.bestType?.element; | |
| 313 if (firstElement == null) { | |
| 314 return null; | |
| 315 } | |
| 316 for (int i = 1; i < variables.length; i++) { | |
| 317 Element element = variables[1].name?.bestType?.element; | |
|
scheglov
2017/03/23 00:05:34
variables[i]
| |
| 318 if (element != firstElement) { | |
| 319 return null; | |
| 320 } | |
| 321 } | |
| 322 return firstElement; | |
| 323 } | |
| 324 | |
| 325 if (node.type == null) { | |
| 326 Token token = node.keyword; | |
| 327 if (token?.keyword == Keyword.VAR) { | |
|
scheglov
2017/03/23 00:05:34
final and const too?
| |
| 328 Element element = getCommonElement(node.variables); | |
| 329 if (element != null) { | |
| 330 computer._addRegionForToken(token, element); | |
| 331 } | |
| 332 } | |
| 333 } | |
| 334 super.visitVariableDeclarationList(node); | |
| 335 } | |
| 336 | |
| 288 void _addConstructorName(AstNode parent, ConstructorName node) { | 337 void _addConstructorName(AstNode parent, ConstructorName node) { |
| 289 Element element = node.staticElement; | 338 Element element = node.staticElement; |
| 290 if (element == null) { | 339 if (element == null) { |
| 291 return; | 340 return; |
| 292 } | 341 } |
| 293 // if a synthetic constructor, navigate to the class | 342 // if a synthetic constructor, navigate to the class |
| 294 if (element.isSynthetic) { | 343 if (element.isSynthetic) { |
| 295 element = element.enclosingElement; | 344 element = element.enclosingElement; |
| 296 } | 345 } |
| 297 // add regions | 346 // add regions |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 323 */ | 372 */ |
| 324 void _addUriDirectiveRegion(UriBasedDirective node, Element element) { | 373 void _addUriDirectiveRegion(UriBasedDirective node, Element element) { |
| 325 if (element != null) { | 374 if (element != null) { |
| 326 Source source = element.source; | 375 Source source = element.source; |
| 327 if (element.context.exists(source)) { | 376 if (element.context.exists(source)) { |
| 328 computer._addRegionForNode(node.uri, element); | 377 computer._addRegionForNode(node.uri, element); |
| 329 } | 378 } |
| 330 } | 379 } |
| 331 } | 380 } |
| 332 } | 381 } |
| OLD | NEW |