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

Unified Diff: pkg/analysis_server/lib/src/domains/analysis/navigation_dart.dart

Issue 2769813005: Allow navigation from var when there is an inferred type (issue 29091) (Closed)
Patch Set: Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/test/analysis/notification_navigation_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/domains/analysis/navigation_dart.dart
diff --git a/pkg/analysis_server/lib/src/domains/analysis/navigation_dart.dart b/pkg/analysis_server/lib/src/domains/analysis/navigation_dart.dart
index 63f10dfeca0b617794673eb08893defd09435b65..99c7131ef0b7e7a614835dc071ae810e1bd349b5 100644
--- a/pkg/analysis_server/lib/src/domains/analysis/navigation_dart.dart
+++ b/pkg/analysis_server/lib/src/domains/analysis/navigation_dart.dart
@@ -10,6 +10,7 @@ import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/token.dart';
import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/dart/element/element.dart';
+import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/src/dart/ast/utilities.dart';
import 'package:analyzer/src/dart/element/element.dart';
import 'package:analyzer/src/generated/engine.dart';
@@ -194,6 +195,21 @@ class _DartNavigationComputerVisitor extends RecursiveAstVisitor {
}
@override
+ visitDeclaredIdentifier(DeclaredIdentifier node) {
+ if (node.type == null) {
+ Token token = node.keyword;
+ if (token?.keyword == Keyword.VAR) {
+ DartType inferredType = node.identifier?.bestType;
+ Element element = inferredType?.element;
+ if (element != null) {
+ computer._addRegionForToken(token, element);
+ }
+ }
+ }
+ super.visitDeclaredIdentifier(node);
+ }
+
+ @override
visitExportDirective(ExportDirective node) {
ExportElement exportElement = node.element;
if (exportElement != null) {
@@ -285,6 +301,39 @@ class _DartNavigationComputerVisitor extends RecursiveAstVisitor {
node.argumentList?.accept(this);
}
+ @override
+ visitVariableDeclarationList(VariableDeclarationList node) {
+ /**
+ * Return the element for the type inferred for each of the variables in the
+ * given list of [variables], or `null` if not all variable have the same
+ * inferred type.
+ */
+ Element getCommonElement(List<VariableDeclaration> variables) {
+ Element firstElement = variables[0].name?.bestType?.element;
+ if (firstElement == null) {
+ return null;
+ }
+ for (int i = 1; i < variables.length; i++) {
+ Element element = variables[1].name?.bestType?.element;
scheglov 2017/03/23 00:05:34 variables[i]
+ if (element != firstElement) {
+ return null;
+ }
+ }
+ return firstElement;
+ }
+
+ if (node.type == null) {
+ Token token = node.keyword;
+ if (token?.keyword == Keyword.VAR) {
scheglov 2017/03/23 00:05:34 final and const too?
+ Element element = getCommonElement(node.variables);
+ if (element != null) {
+ computer._addRegionForToken(token, element);
+ }
+ }
+ }
+ super.visitVariableDeclarationList(node);
+ }
+
void _addConstructorName(AstNode parent, ConstructorName node) {
Element element = node.staticElement;
if (element == null) {
« 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