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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/engine.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';
11 import 'package:analyzer/src/generated/element.dart'; 11 import 'package:analyzer/src/generated/element.dart';
12 import 'package:analyzer/src/generated/scanner.dart'; 12 import 'package:analyzer/src/generated/scanner.dart';
13 import 'package:analyzer/src/generated/source.dart';
13 14
14 /** 15 /**
15 * A computer for navigation regions in a Dart [CompilationUnit]. 16 * A computer for navigation regions in a Dart [CompilationUnit].
16 */ 17 */
17 class DartUnitNavigationComputer { 18 class DartUnitNavigationComputer {
18 final CompilationUnit _unit; 19 final CompilationUnit _unit;
19 20
20 final List<String> files = <String>[]; 21 final List<String> files = <String>[];
21 final Map<String, int> fileMap = new HashMap<String, int>(); 22 final Map<String, int> fileMap = new HashMap<String, int>();
22 final List<protocol.NavigationTarget> targets = <protocol.NavigationTarget>[]; 23 final List<protocol.NavigationTarget> targets = <protocol.NavigationTarget>[];
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 } else if (parent is ConstructorDeclaration && 155 } else if (parent is ConstructorDeclaration &&
155 parent.redirectedConstructor == node) { 156 parent.redirectedConstructor == node) {
156 _addConstructorName(node, node); 157 _addConstructorName(node, node);
157 } 158 }
158 } 159 }
159 160
160 @override 161 @override
161 visitExportDirective(ExportDirective node) { 162 visitExportDirective(ExportDirective node) {
162 ExportElement exportElement = node.element; 163 ExportElement exportElement = node.element;
163 if (exportElement != null) { 164 if (exportElement != null) {
164 Element element = exportElement.exportedLibrary; 165 Element libraryElement = exportElement.exportedLibrary;
165 computer._addRegion_tokenStart_nodeEnd(node.keyword, node.uri, element); 166 _addUriDirectiveRegion(node, libraryElement);
166 } 167 }
167 super.visitExportDirective(node); 168 super.visitExportDirective(node);
168 } 169 }
169 170
170 @override 171 @override
171 visitImportDirective(ImportDirective node) { 172 visitImportDirective(ImportDirective node) {
172 ImportElement importElement = node.element; 173 ImportElement importElement = node.element;
173 if (importElement != null) { 174 if (importElement != null) {
174 Element element = importElement.importedLibrary; 175 Element libraryElement = importElement.importedLibrary;
175 computer._addRegion_tokenStart_nodeEnd(node.keyword, node.uri, element); 176 _addUriDirectiveRegion(node, libraryElement);
176 } 177 }
177 super.visitImportDirective(node); 178 super.visitImportDirective(node);
178 } 179 }
179 180
180 @override 181 @override
181 visitIndexExpression(IndexExpression node) { 182 visitIndexExpression(IndexExpression node) {
182 super.visitIndexExpression(node); 183 super.visitIndexExpression(node);
183 computer._addRegionForToken(node.rightBracket, node.bestElement); 184 computer._addRegionForToken(node.rightBracket, node.bestElement);
184 } 185 }
185 186
186 @override 187 @override
187 visitPartDirective(PartDirective node) { 188 visitPartDirective(PartDirective node) {
188 computer._addRegion_tokenStart_nodeEnd( 189 _addUriDirectiveRegion(node, node.element);
189 node.keyword, node.uri, node.element);
190 super.visitPartDirective(node); 190 super.visitPartDirective(node);
191 } 191 }
192 192
193 @override 193 @override
194 visitPartOfDirective(PartOfDirective node) { 194 visitPartOfDirective(PartOfDirective node) {
195 computer._addRegion_tokenStart_nodeEnd( 195 computer._addRegion_tokenStart_nodeEnd(
196 node.keyword, node.libraryName, node.element); 196 node.keyword, node.libraryName, node.element);
197 super.visitPartOfDirective(node); 197 super.visitPartOfDirective(node);
198 } 198 }
199 199
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 computer._addRegion_nodeStart_nodeEnd(parent, typeName.name, element); 253 computer._addRegion_nodeStart_nodeEnd(parent, typeName.name, element);
254 // <TypeA, TypeB> 254 // <TypeA, TypeB>
255 typeArguments.accept(this); 255 typeArguments.accept(this);
256 // optional ".name" 256 // optional ".name"
257 if (node.period != null) { 257 if (node.period != null) {
258 computer._addRegion_tokenStart_nodeEnd(node.period, node, element); 258 computer._addRegion_tokenStart_nodeEnd(node.period, node, element);
259 } 259 }
260 } 260 }
261 } 261 }
262 262
263 /**
264 * If the source of the given [element] (referenced by the [node]) exists,
265 * then add the navigation region from the [node] to the [element].
266 */
267 void _addUriDirectiveRegion(UriBasedDirective node, Element element) {
268 if (element != null) {
269 Source source = element.source;
270 if (element.context.exists(source)) {
271 computer._addRegion_tokenStart_nodeEnd(node.keyword, node.uri, element);
272 }
273 }
274 }
275
263 void _safelyVisit(AstNode node) { 276 void _safelyVisit(AstNode node) {
264 if (node != null) { 277 if (node != null) {
265 node.accept(this); 278 node.accept(this);
266 } 279 }
267 } 280 }
268 } 281 }
OLDNEW
« 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