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

Unified Diff: pkg/analysis_server/lib/src/services/completion/statement/statement_completion.dart

Issue 2837063003: Add colon to switch cases and default (Closed)
Patch Set: reformat Created 3 years, 8 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/analysis_server/test/services/completion/statement/statement_completion_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/services/completion/statement/statement_completion.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/statement/statement_completion.dart b/pkg/analysis_server/lib/src/services/completion/statement/statement_completion.dart
index 95db11c024434aa076c5ec9a870f5238b34b41d2..fe9b12ccc24696bb49c746b39cab09493223fc28 100644
--- a/pkg/analysis_server/lib/src/services/completion/statement/statement_completion.dart
+++ b/pkg/analysis_server/lib/src/services/completion/statement/statement_completion.dart
@@ -177,14 +177,9 @@ class StatementCompletionProcessor {
if (newNode is Block) {
Block blockNode = newNode;
if (blockNode.statements.isNotEmpty) {
- node = blockNode.statements[blockNode.statements.length - 1];
+ node = blockNode.statements.last;
} else {
- newNode = node.getAncestor((n) => n is CatchClause);
- if (newNode != null) {
- node = newNode.parent;
- } else {
- node = node.getAncestor((n) => n is Statement).parent;
- }
+ node = newNode;
}
} else {
node = newNode;
Brian Wilkerson 2017/04/24 21:07:40 Given that 'node' is set to 'newNode' in two third
messick 2017/04/25 18:13:23 Acknowledged.
@@ -648,6 +643,17 @@ class StatementCompletionProcessor {
// See https://github.com/dart-lang/sdk/issues/29391
sb.append(' ');
_appendEmptyBraces(sb, exitPosition == null);
+ } else {
+ SwitchMember member = _findInvalidElement(switchNode.members);
+ if (member != null) {
+ if (member.colon.isSynthetic) {
+ int loc =
+ member is SwitchCase ? member.expression.end : member.keyword.end;
+ sb = new SourceBuilder(file, loc);
+ sb.append(': ');
+ exitPosition = new Position(file, loc + 2);
+ }
+ }
}
_insertBuilder(sb);
_setCompletion(DartStatementCompletion.COMPLETE_SWITCH_STMT);
@@ -677,7 +683,8 @@ class StatementCompletionProcessor {
_appendEmptyBraces(sb, true);
_insertBuilder(sb);
sb = null;
- } else if ((catchNode = _findInvalidCatch(tryNode.catchClauses)) != null) {
+ } else if ((catchNode = _findInvalidElement(tryNode.catchClauses)) !=
+ null) {
if (catchNode.onKeyword != null) {
if (catchNode.exceptionType.length == 0) {
String src = utils.getNodeText(catchNode);
@@ -771,7 +778,7 @@ class StatementCompletionProcessor {
return null;
}
- CatchClause _findInvalidCatch(NodeList<CatchClause> list) {
+ T _findInvalidElement<T extends AstNode>(NodeList<T> list) {
return list.firstWhere(
(catchClause) =>
Brian Wilkerson 2017/04/24 21:07:40 Given that the method has been generalized, perhap
messick 2017/04/25 18:13:23 Acknowledged.
selectionOffset >= catchClause.offset &&
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/completion/statement/statement_completion_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698