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

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

Issue 1402353009: [Atom] Issue 424. Fix for 'getNavigation' and index expressions. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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/analysis_server/test/analysis/get_navigation_test.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) 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/src/generated/ast.dart'; 9 import 'package:analyzer/src/generated/ast.dart';
10 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 if (importElement != null) { 191 if (importElement != null) {
192 Element libraryElement = importElement.importedLibrary; 192 Element libraryElement = importElement.importedLibrary;
193 _addUriDirectiveRegion(node, libraryElement); 193 _addUriDirectiveRegion(node, libraryElement);
194 } 194 }
195 super.visitImportDirective(node); 195 super.visitImportDirective(node);
196 } 196 }
197 197
198 @override 198 @override
199 visitIndexExpression(IndexExpression node) { 199 visitIndexExpression(IndexExpression node) {
200 super.visitIndexExpression(node); 200 super.visitIndexExpression(node);
201 computer._addRegionForToken(node.rightBracket, node.bestElement); 201 MethodElement element = node.bestElement;
202 computer._addRegionForToken(node.leftBracket, element);
203 computer._addRegionForToken(node.rightBracket, element);
202 } 204 }
203 205
204 @override 206 @override
205 visitLibraryDirective(LibraryDirective node) { 207 visitLibraryDirective(LibraryDirective node) {
206 computer._addRegionForNode(node.name, node.element); 208 computer._addRegionForNode(node.name, node.element);
207 } 209 }
208 210
209 @override 211 @override
210 visitPartDirective(PartDirective node) { 212 visitPartDirective(PartDirective node) {
211 _addUriDirectiveRegion(node, node.element); 213 _addUriDirectiveRegion(node, node.element);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 * An AST visitor that forwards nodes intersecting with the range from 305 * An AST visitor that forwards nodes intersecting with the range from
304 * [start] to [end] to the given [visitor]. 306 * [start] to [end] to the given [visitor].
305 */ 307 */
306 class _DartRangeAstVisitor extends UnifyingAstVisitor { 308 class _DartRangeAstVisitor extends UnifyingAstVisitor {
307 final int start; 309 final int start;
308 final int end; 310 final int end;
309 final AstVisitor visitor; 311 final AstVisitor visitor;
310 312
311 _DartRangeAstVisitor(this.start, this.end, this.visitor); 313 _DartRangeAstVisitor(this.start, this.end, this.visitor);
312 314
313 bool isInRange(int offset) {
314 return start <= offset && offset <= end;
315 }
316
317 @override 315 @override
318 visitNode(AstNode node) { 316 visitNode(AstNode node) {
319 // The node ends before the range starts. 317 // The node ends before the range starts.
320 if (node.end < start) { 318 if (node.end < start) {
321 return; 319 return;
322 } 320 }
323 // The node starts after the range ends. 321 // The node starts after the range ends.
324 if (node.offset > end) { 322 if (node.offset > end) {
325 return; 323 return;
326 } 324 }
327 // The node starts or ends in the range. 325 // The node starts or ends in the range.
328 if (node is! CompilationUnit) { 326 if (node is! CompilationUnit) {
329 if (isInRange(node.offset) || isInRange(node.end) || node is Directive) { 327 if (node is Directive) {
330 node.accept(visitor); 328 node.accept(visitor);
331 return; 329 return;
332 } 330 }
331 if (_isNodeInRange(node)) {
332 while (_isNodeInRange(node)) {
Brian Wilkerson 2015/10/25 15:28:04 I don't understand this while loop, so I'm probabl
scheglov 2015/10/25 18:29:44 Thank you. Reworked.
333 node = node.parent;
334 }
335 node.accept(visitor);
336 return;
337 }
333 } 338 }
334 // Go deeper. 339 // Go deeper.
335 super.visitNode(node); 340 super.visitNode(node);
336 } 341 }
342
343 bool _isNodeInRange(AstNode node) {
344 return _isOffsetInRange(node.offset) || _isOffsetInRange(node.end);
345 }
346
347 bool _isOffsetInRange(int offset) {
348 return start <= offset && offset <= end;
349 }
337 } 350 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/analysis/get_navigation_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698