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

Unified Diff: pkg/analysis_server/lib/src/computer/computer_navigation.dart

Issue 1180883003: Don't create navigation regions for not existing sources. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 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/analyzer/lib/src/generated/engine.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/computer/computer_navigation.dart
diff --git a/pkg/analysis_server/lib/src/computer/computer_navigation.dart b/pkg/analysis_server/lib/src/computer/computer_navigation.dart
index 2236ee4d5cf0cb912c4e3e92d405f450e14f24cd..504bf407323b1315f48b1073cef074be82fb5989 100644
--- a/pkg/analysis_server/lib/src/computer/computer_navigation.dart
+++ b/pkg/analysis_server/lib/src/computer/computer_navigation.dart
@@ -10,6 +10,7 @@ import 'package:analysis_server/src/protocol_server.dart' as protocol;
import 'package:analyzer/src/generated/ast.dart';
import 'package:analyzer/src/generated/element.dart';
import 'package:analyzer/src/generated/scanner.dart';
+import 'package:analyzer/src/generated/source.dart';
/**
* A computer for navigation regions in a Dart [CompilationUnit].
@@ -161,8 +162,8 @@ class _DartUnitNavigationComputerVisitor extends RecursiveAstVisitor {
visitExportDirective(ExportDirective node) {
ExportElement exportElement = node.element;
if (exportElement != null) {
- Element element = exportElement.exportedLibrary;
- computer._addRegion_tokenStart_nodeEnd(node.keyword, node.uri, element);
+ Element libraryElement = exportElement.exportedLibrary;
+ _addUriDirectiveRegion(node, libraryElement);
}
super.visitExportDirective(node);
}
@@ -171,8 +172,8 @@ class _DartUnitNavigationComputerVisitor extends RecursiveAstVisitor {
visitImportDirective(ImportDirective node) {
ImportElement importElement = node.element;
if (importElement != null) {
- Element element = importElement.importedLibrary;
- computer._addRegion_tokenStart_nodeEnd(node.keyword, node.uri, element);
+ Element libraryElement = importElement.importedLibrary;
+ _addUriDirectiveRegion(node, libraryElement);
}
super.visitImportDirective(node);
}
@@ -185,8 +186,7 @@ class _DartUnitNavigationComputerVisitor extends RecursiveAstVisitor {
@override
visitPartDirective(PartDirective node) {
- computer._addRegion_tokenStart_nodeEnd(
- node.keyword, node.uri, node.element);
+ _addUriDirectiveRegion(node, node.element);
super.visitPartDirective(node);
}
@@ -260,6 +260,19 @@ class _DartUnitNavigationComputerVisitor extends RecursiveAstVisitor {
}
}
+ /**
+ * If the source of the given [element] (referenced by the [node]) exists,
+ * then add the navigation region from the [node] to the [element].
+ */
+ void _addUriDirectiveRegion(UriBasedDirective node, Element element) {
+ if (element != null) {
+ Source source = element.source;
+ if (element.context.exists(source)) {
+ computer._addRegion_tokenStart_nodeEnd(node.keyword, node.uri, element);
+ }
+ }
+ }
+
void _safelyVisit(AstNode node) {
if (node != null) {
node.accept(this);
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/engine.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698