| 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 // 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 services.completion.computer.dart.keyword; | 5 library services.completion.computer.dart.keyword; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/protocol.dart'; | 9 import 'package:analysis_server/src/protocol.dart'; |
| 10 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; | 10 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 /** | 38 /** |
| 39 * The identifier visited or `null` if not visited. | 39 * The identifier visited or `null` if not visited. |
| 40 */ | 40 */ |
| 41 SimpleIdentifier identifier; | 41 SimpleIdentifier identifier; |
| 42 | 42 |
| 43 _KeywordVisitor(this.request); | 43 _KeywordVisitor(this.request); |
| 44 | 44 |
| 45 @override | 45 @override |
| 46 visitBlock(Block node) { | 46 visitBlock(Block node) { |
| 47 _addSuggestions( | 47 if (_isInClassMemberBody(node)) { |
| 48 [ | 48 _addSuggestions( |
| 49 Keyword.ASSERT, | 49 [ |
| 50 Keyword.CASE, | 50 Keyword.ASSERT, |
| 51 Keyword.CONTINUE, | 51 Keyword.CASE, |
| 52 Keyword.DO, | 52 Keyword.CONTINUE, |
| 53 Keyword.FACTORY, | 53 Keyword.DO, |
| 54 Keyword.FINAL, | 54 Keyword.FINAL, |
| 55 Keyword.FOR, | 55 Keyword.FOR, |
| 56 Keyword.IF, | 56 Keyword.IF, |
| 57 Keyword.NEW, | 57 Keyword.NEW, |
| 58 Keyword.RETHROW, | 58 Keyword.RETHROW, |
| 59 Keyword.RETURN, | 59 Keyword.RETURN, |
| 60 Keyword.SUPER, | 60 Keyword.SUPER, |
| 61 Keyword.SWITCH, | 61 Keyword.SWITCH, |
| 62 Keyword.THIS, | 62 Keyword.THIS, |
| 63 Keyword.THROW, | 63 Keyword.THROW, |
| 64 Keyword.TRY, | 64 Keyword.TRY, |
| 65 Keyword.VAR, | 65 Keyword.VAR, |
| 66 Keyword.VOID, | 66 Keyword.VOID, |
| 67 Keyword.WHILE]); | 67 Keyword.WHILE]); |
| 68 } else { |
| 69 _addSuggestions( |
| 70 [ |
| 71 Keyword.ASSERT, |
| 72 Keyword.CASE, |
| 73 Keyword.CONTINUE, |
| 74 Keyword.DO, |
| 75 Keyword.FINAL, |
| 76 Keyword.FOR, |
| 77 Keyword.IF, |
| 78 Keyword.NEW, |
| 79 Keyword.RETHROW, |
| 80 Keyword.RETURN, |
| 81 Keyword.SWITCH, |
| 82 Keyword.THROW, |
| 83 Keyword.TRY, |
| 84 Keyword.VAR, |
| 85 Keyword.VOID, |
| 86 Keyword.WHILE]); |
| 87 } |
| 68 } | 88 } |
| 69 | 89 |
| 70 @override | 90 @override |
| 71 visitClassDeclaration(ClassDeclaration node) { | 91 visitClassDeclaration(ClassDeclaration node) { |
| 72 // Don't suggest class name | 92 // Don't suggest class name |
| 73 if (node.name == identifier) { | 93 if (node.name == identifier) { |
| 74 return; | 94 return; |
| 75 } | 95 } |
| 76 // Inside the class declaration { } | 96 // Inside the class declaration { } |
| 77 if (request.offset > node.leftBracket.offset) { | 97 if (request.offset > node.leftBracket.offset) { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 if (request.offset == node.end) { | 244 if (request.offset == node.end) { |
| 225 Token token = node.endToken; | 245 Token token = node.endToken; |
| 226 if (token != null && !token.isSynthetic) { | 246 if (token != null && !token.isSynthetic) { |
| 227 if (token.lexeme == ';' || token.lexeme == '}') { | 247 if (token.lexeme == ';' || token.lexeme == '}') { |
| 228 return true; | 248 return true; |
| 229 } | 249 } |
| 230 } | 250 } |
| 231 } | 251 } |
| 232 return false; | 252 return false; |
| 233 } | 253 } |
| 254 |
| 255 static bool _isInClassMemberBody(AstNode node) { |
| 256 while (true) { |
| 257 AstNode body = node.getAncestor((n) => n is FunctionBody); |
| 258 if (body == null) { |
| 259 return false; |
| 260 } |
| 261 AstNode parent = body.parent; |
| 262 if (parent is ConstructorDeclaration || parent is MethodDeclaration) { |
| 263 return true; |
| 264 } |
| 265 node = parent; |
| 266 } |
| 267 } |
| 234 } | 268 } |
| OLD | NEW |