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.contributor.dart.keyword; | 5 library services.completion.contributor.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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 @override | 45 @override |
46 visitArgumentList(ArgumentList node) { | 46 visitArgumentList(ArgumentList node) { |
47 if (entity == node.rightParenthesis || | 47 if (entity == node.rightParenthesis || |
48 (entity is SimpleIdentifier && node.arguments.contains(entity))) { | 48 (entity is SimpleIdentifier && node.arguments.contains(entity))) { |
49 _addExpressionKeywords(node); | 49 _addExpressionKeywords(node); |
50 } | 50 } |
51 } | 51 } |
52 | 52 |
53 @override | 53 @override |
54 visitBlock(Block node) { | 54 visitBlock(Block node) { |
| 55 if (entity is ExpressionStatement) { |
| 56 Expression expression = (entity as ExpressionStatement).expression; |
| 57 if (expression is SimpleIdentifier) { |
| 58 Token token = expression.token; |
| 59 Token previous = token.previous; |
| 60 if (previous.isSynthetic) { |
| 61 previous = previous.previous; |
| 62 } |
| 63 Token next = token.next; |
| 64 if (next.isSynthetic) { |
| 65 next = next.next; |
| 66 } |
| 67 if (previous.lexeme == ')' && next.lexeme == '{') { |
| 68 _addSuggestion2(ASYNC); |
| 69 } |
| 70 } |
| 71 } |
55 _addStatementKeywords(node); | 72 _addStatementKeywords(node); |
56 } | 73 } |
57 | 74 |
58 @override | 75 @override |
59 visitClassDeclaration(ClassDeclaration node) { | 76 visitClassDeclaration(ClassDeclaration node) { |
60 // Don't suggest class name | 77 // Don't suggest class name |
61 if (entity == node.name) { | 78 if (entity == node.name) { |
62 return; | 79 return; |
63 } | 80 } |
64 if (entity == node.rightBracket) { | 81 if (entity == node.rightBracket) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 AstNode constructorDecl = | 161 AstNode constructorDecl = |
145 node.getAncestor((p) => p is ConstructorDeclaration); | 162 node.getAncestor((p) => p is ConstructorDeclaration); |
146 if (constructorDecl != null) { | 163 if (constructorDecl != null) { |
147 _addSuggestions([Keyword.THIS]); | 164 _addSuggestions([Keyword.THIS]); |
148 } | 165 } |
149 } | 166 } |
150 | 167 |
151 @override | 168 @override |
152 visitFunctionExpression(FunctionExpression node) { | 169 visitFunctionExpression(FunctionExpression node) { |
153 if (entity == node.body) { | 170 if (entity == node.body) { |
154 _addSuggestion2(ASYNC, relevance: DART_RELEVANCE_HIGH); | 171 if (!node.body.isAsynchronous) { |
| 172 _addSuggestion2(ASYNC, relevance: DART_RELEVANCE_HIGH); |
| 173 } |
155 if (node.body is EmptyFunctionBody && | 174 if (node.body is EmptyFunctionBody && |
156 node.parent is FunctionDeclaration && | 175 node.parent is FunctionDeclaration && |
157 node.parent.parent is CompilationUnit) { | 176 node.parent.parent is CompilationUnit) { |
158 _addCompilationUnitKeywords(); | 177 _addCompilationUnitKeywords(); |
159 } | 178 } |
160 } | 179 } |
161 } | 180 } |
162 | 181 |
163 @override | 182 @override |
164 visitIfStatement(IfStatement node) { | 183 visitIfStatement(IfStatement node) { |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 return false; | 390 return false; |
372 } | 391 } |
373 AstNode parent = body.parent; | 392 AstNode parent = body.parent; |
374 if (parent is ConstructorDeclaration || parent is MethodDeclaration) { | 393 if (parent is ConstructorDeclaration || parent is MethodDeclaration) { |
375 return true; | 394 return true; |
376 } | 395 } |
377 node = parent; | 396 node = parent; |
378 } | 397 } |
379 } | 398 } |
380 } | 399 } |
OLD | NEW |