| OLD | NEW |
| 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 |
| 3 // 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 |
| 4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 library services.completion.dart.keyword; | 6 library services.completion.dart.keyword; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 | 9 |
| 10 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 10 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 } | 219 } |
| 220 } | 220 } |
| 221 | 221 |
| 222 @override | 222 @override |
| 223 visitForStatement(ForStatement node) { | 223 visitForStatement(ForStatement node) { |
| 224 // Actual: for (va^) | 224 // Actual: for (va^) |
| 225 // Parsed: for (va^; ;) | 225 // Parsed: for (va^; ;) |
| 226 if (node.initialization == entity && entity is SimpleIdentifier) { | 226 if (node.initialization == entity && entity is SimpleIdentifier) { |
| 227 if (_isNextTokenSynthetic(entity, TokenType.SEMICOLON)) { | 227 if (_isNextTokenSynthetic(entity, TokenType.SEMICOLON)) { |
| 228 _addSuggestion(Keyword.VAR, DART_RELEVANCE_HIGH); | 228 _addSuggestion(Keyword.VAR, DART_RELEVANCE_HIGH); |
| 229 _addSuggestion(Keyword.FINAL, DART_RELEVANCE_HIGH); | |
| 230 } | 229 } |
| 231 } | 230 } |
| 232 // Actual: for (int x i^) | 231 // Actual: for (int x i^) |
| 233 // Parsed: for (int x; i^;) | 232 // Parsed: for (int x; i^;) |
| 234 // Handle the degenerate case while typing - for (int x i^) | 233 // Handle the degenerate case while typing - for (int x i^) |
| 235 if (node.condition == entity && entity is SimpleIdentifier) { | 234 if (node.condition == entity && |
| 235 entity is SimpleIdentifier && |
| 236 node.variables != null) { |
| 236 if (_isPreviousTokenSynthetic(entity, TokenType.SEMICOLON)) { | 237 if (_isPreviousTokenSynthetic(entity, TokenType.SEMICOLON)) { |
| 237 _addSuggestion(Keyword.IN, DART_RELEVANCE_HIGH); | 238 _addSuggestion(Keyword.IN, DART_RELEVANCE_HIGH); |
| 238 } | 239 } |
| 239 } | 240 } |
| 240 } | 241 } |
| 241 | 242 |
| 242 @override | 243 @override |
| 243 visitFunctionExpression(FunctionExpression node) { | 244 visitFunctionExpression(FunctionExpression node) { |
| 244 if (entity == node.body) { | 245 if (entity == node.body) { |
| 245 FunctionBody body = node.body; | 246 FunctionBody body = node.body; |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 | 595 |
| 595 static bool _isPreviousTokenSynthetic(Object entity, TokenType type) { | 596 static bool _isPreviousTokenSynthetic(Object entity, TokenType type) { |
| 596 if (entity is AstNode) { | 597 if (entity is AstNode) { |
| 597 Token token = entity.beginToken; | 598 Token token = entity.beginToken; |
| 598 Token previousToken = token.previous; | 599 Token previousToken = token.previous; |
| 599 return previousToken.isSynthetic && previousToken.type == type; | 600 return previousToken.isSynthetic && previousToken.type == type; |
| 600 } | 601 } |
| 601 return false; | 602 return false; |
| 602 } | 603 } |
| 603 } | 604 } |
| OLD | NEW |