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

Side by Side Diff: pkg/analysis_server/lib/src/services/completion/keyword_contributor.dart

Issue 1360123003: only suggest rethrow inside catch block - fixes #24214 (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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/analysis_server/test/services/completion/keyword_contributor_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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2
2 // for details. All rights reserved. Use of this source code is governed by a 3 // 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. 4 // BSD-style license that can be found in the LICENSE file.
4 5
5 library services.completion.contributor.dart.keyword; 6 library services.completion.contributor.dart.keyword;
6 7
7 import 'dart:async'; 8 import 'dart:async';
8 9
9 import 'package:analysis_server/src/protocol.dart'; 10 import 'package:analysis_server/src/protocol.dart';
10 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart'; 11 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart';
11 import 'package:analyzer/src/generated/ast.dart'; 12 import 'package:analyzer/src/generated/ast.dart';
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 Token next = token.next; 64 Token next = token.next;
64 if (next.isSynthetic) { 65 if (next.isSynthetic) {
65 next = next.next; 66 next = next.next;
66 } 67 }
67 if (previous.lexeme == ')' && next.lexeme == '{') { 68 if (previous.lexeme == ')' && next.lexeme == '{') {
68 _addSuggestion2(ASYNC); 69 _addSuggestion2(ASYNC);
69 } 70 }
70 } 71 }
71 } 72 }
72 _addStatementKeywords(node); 73 _addStatementKeywords(node);
74 if (_inCatchClause(node)) {
75 _addSuggestion(Keyword.RETHROW, DART_RELEVANCE_KEYWORD - 1);
76 }
73 } 77 }
74 78
75 @override 79 @override
76 visitClassDeclaration(ClassDeclaration node) { 80 visitClassDeclaration(ClassDeclaration node) {
77 // Don't suggest class name 81 // Don't suggest class name
78 if (entity == node.name) { 82 if (entity == node.name) {
79 return; 83 return;
80 } 84 }
81 if (entity == node.rightBracket) { 85 if (entity == node.rightBracket) {
82 _addClassBodyKeywords(); 86 _addClassBodyKeywords();
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 Keyword.IF, 443 Keyword.IF,
440 Keyword.NEW, 444 Keyword.NEW,
441 Keyword.RETURN, 445 Keyword.RETURN,
442 Keyword.SWITCH, 446 Keyword.SWITCH,
443 Keyword.THROW, 447 Keyword.THROW,
444 Keyword.TRY, 448 Keyword.TRY,
445 Keyword.VAR, 449 Keyword.VAR,
446 Keyword.VOID, 450 Keyword.VOID,
447 Keyword.WHILE 451 Keyword.WHILE
448 ]); 452 ]);
449 _addSuggestion(Keyword.RETHROW, DART_RELEVANCE_KEYWORD - 1);
450 } 453 }
451 454
452 void _addSuggestion(Keyword keyword, 455 void _addSuggestion(Keyword keyword,
453 [int relevance = DART_RELEVANCE_KEYWORD]) { 456 [int relevance = DART_RELEVANCE_KEYWORD]) {
454 _addSuggestion2(keyword.syntax, relevance: relevance); 457 _addSuggestion2(keyword.syntax, relevance: relevance);
455 } 458 }
456 459
457 void _addSuggestion2(String completion, 460 void _addSuggestion2(String completion,
458 {int offset, int relevance: DART_RELEVANCE_KEYWORD}) { 461 {int offset, int relevance: DART_RELEVANCE_KEYWORD}) {
459 if (offset == null) { 462 if (offset == null) {
(...skipping 14 matching lines...) Expand all
474 keywords.forEach((Keyword keyword) { 477 keywords.forEach((Keyword keyword) {
475 _addSuggestion(keyword, relevance); 478 _addSuggestion(keyword, relevance);
476 }); 479 });
477 } 480 }
478 481
479 bool _inAsyncMethodOrFunction(AstNode node) { 482 bool _inAsyncMethodOrFunction(AstNode node) {
480 FunctionBody body = node.getAncestor((n) => n is FunctionBody); 483 FunctionBody body = node.getAncestor((n) => n is FunctionBody);
481 return body != null && body.isAsynchronous; 484 return body != null && body.isAsynchronous;
482 } 485 }
483 486
487 bool _inCatchClause(Block node) =>
488 node.getAncestor((p) => p is CatchClause) != null;
489
484 bool _inClassMemberBody(AstNode node) { 490 bool _inClassMemberBody(AstNode node) {
485 while (true) { 491 while (true) {
486 AstNode body = node.getAncestor((n) => n is FunctionBody); 492 AstNode body = node.getAncestor((n) => n is FunctionBody);
487 if (body == null) { 493 if (body == null) {
488 return false; 494 return false;
489 } 495 }
490 AstNode parent = body.parent; 496 AstNode parent = body.parent;
491 if (parent is ConstructorDeclaration || parent is MethodDeclaration) { 497 if (parent is ConstructorDeclaration || parent is MethodDeclaration) {
492 return true; 498 return true;
493 } 499 }
(...skipping 10 matching lines...) Expand all
504 510
505 bool _inLoop(AstNode node) => 511 bool _inLoop(AstNode node) =>
506 _inDoLoop(node) || _inForLoop(node) || _inWhileLoop(node); 512 _inDoLoop(node) || _inForLoop(node) || _inWhileLoop(node);
507 513
508 bool _inSwitch(AstNode node) => 514 bool _inSwitch(AstNode node) =>
509 node.getAncestor((p) => p is SwitchStatement) != null; 515 node.getAncestor((p) => p is SwitchStatement) != null;
510 516
511 bool _inWhileLoop(AstNode node) => 517 bool _inWhileLoop(AstNode node) =>
512 node.getAncestor((p) => p is WhileStatement) != null; 518 node.getAncestor((p) => p is WhileStatement) != null;
513 } 519 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/completion/keyword_contributor_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698