Skip to content

Commit 6e441f6

Browse files
author
danrubel
committed
only suggest rethrow inside catch block - fixes #24214
[email protected] Review URL: https://codereview.chromium.org//1360123003 .
1 parent f2d97d1 commit 6e441f6

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

pkg/analysis_server/lib/src/services/completion/keyword_contributor.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2+
23
// for details. All rights reserved. Use of this source code is governed by a
34
// BSD-style license that can be found in the LICENSE file.
45

@@ -70,6 +71,9 @@ class _KeywordVisitor extends GeneralizingAstVisitor {
7071
}
7172
}
7273
_addStatementKeywords(node);
74+
if (_inCatchClause(node)) {
75+
_addSuggestion(Keyword.RETHROW, DART_RELEVANCE_KEYWORD - 1);
76+
}
7377
}
7478

7579
@override
@@ -446,7 +450,6 @@ class _KeywordVisitor extends GeneralizingAstVisitor {
446450
Keyword.VOID,
447451
Keyword.WHILE
448452
]);
449-
_addSuggestion(Keyword.RETHROW, DART_RELEVANCE_KEYWORD - 1);
450453
}
451454

452455
void _addSuggestion(Keyword keyword,
@@ -481,6 +484,9 @@ class _KeywordVisitor extends GeneralizingAstVisitor {
481484
return body != null && body.isAsynchronous;
482485
}
483486

487+
bool _inCatchClause(Block node) =>
488+
node.getAncestor((p) => p is CatchClause) != null;
489+
484490
bool _inClassMemberBody(AstNode node) {
485491
while (true) {
486492
AstNode body = node.getAncestor((n) => n is FunctionBody);

pkg/analysis_server/test/services/completion/keyword_contributor_test.dart

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ class KeywordContributorTest extends AbstractCompletionTest {
8585
Keyword.FOR,
8686
Keyword.IF,
8787
Keyword.NEW,
88-
Keyword.RETHROW,
8988
Keyword.RETURN,
9089
Keyword.SUPER,
9190
Keyword.SWITCH,
@@ -107,7 +106,6 @@ class KeywordContributorTest extends AbstractCompletionTest {
107106
Keyword.FOR,
108107
Keyword.IF,
109108
Keyword.NEW,
110-
Keyword.RETHROW,
111109
Keyword.RETURN,
112110
Keyword.SUPER,
113111
Keyword.SWITCH,
@@ -130,7 +128,6 @@ class KeywordContributorTest extends AbstractCompletionTest {
130128
Keyword.FOR,
131129
Keyword.IF,
132130
Keyword.NEW,
133-
Keyword.RETHROW,
134131
Keyword.RETURN,
135132
Keyword.SUPER,
136133
Keyword.SWITCH,
@@ -153,7 +150,6 @@ class KeywordContributorTest extends AbstractCompletionTest {
153150
Keyword.FOR,
154151
Keyword.IF,
155152
Keyword.NEW,
156-
Keyword.RETHROW,
157153
Keyword.RETURN,
158154
Keyword.SWITCH,
159155
Keyword.THROW,
@@ -171,7 +167,6 @@ class KeywordContributorTest extends AbstractCompletionTest {
171167
Keyword.FOR,
172168
Keyword.IF,
173169
Keyword.NEW,
174-
Keyword.RETHROW,
175170
Keyword.RETURN,
176171
Keyword.SWITCH,
177172
Keyword.THROW,
@@ -191,7 +186,6 @@ class KeywordContributorTest extends AbstractCompletionTest {
191186
Keyword.FOR,
192187
Keyword.IF,
193188
Keyword.NEW,
194-
Keyword.RETHROW,
195189
Keyword.RETURN,
196190
Keyword.SWITCH,
197191
Keyword.THROW,
@@ -613,6 +607,16 @@ class KeywordContributorTest extends AbstractCompletionTest {
613607
relevance: DART_RELEVANCE_KEYWORD);
614608
}
615609

610+
test_catch() {
611+
addTestSource('main() {try {} catch (e) {^}}}');
612+
expect(computeFast(), isTrue);
613+
var keywords = <Keyword>[];
614+
keywords.addAll(STMT_START_OUTSIDE_CLASS);
615+
keywords.add(Keyword.RETHROW);
616+
assertSuggestKeywords(keywords,
617+
relevance: DART_RELEVANCE_KEYWORD);
618+
}
619+
616620
test_for_break_continue2() {
617621
addTestSource('class A {foo() {for (int x in myList) {^}}}');
618622
expect(computeFast(), isTrue);

0 commit comments

Comments
 (0)