Chromium Code Reviews| 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.dart.optype; | 5 library services.completion.dart.optype; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/protocol_server.dart' hide Element; | 7 import 'package:analysis_server/src/protocol_server.dart' hide Element; |
| 8 import 'package:analysis_server/src/provisional/completion/dart/completion_dart. dart'; | 8 import 'package:analysis_server/src/provisional/completion/dart/completion_dart. dart'; |
| 9 import 'package:analysis_server/src/provisional/completion/dart/completion_targe t.dart'; | 9 import 'package:analysis_server/src/provisional/completion/dart/completion_targe t.dart'; |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 469 // Actual: for (var v i^) | 469 // Actual: for (var v i^) |
| 470 // Parsed: for (var i; i^;) | 470 // Parsed: for (var i; i^;) |
| 471 } else if (entity is Token && | 471 } else if (entity is Token && |
| 472 entity.isSynthetic && | 472 entity.isSynthetic && |
| 473 node.leftSeparator == entity) { | 473 node.leftSeparator == entity) { |
| 474 // Actual: for (String ^) | 474 // Actual: for (String ^) |
| 475 // Parsed: for (String; ;) | 475 // Parsed: for (String; ;) |
| 476 // ^ | 476 // ^ |
| 477 optype.includeVarNameSuggestions = true; | 477 optype.includeVarNameSuggestions = true; |
| 478 } else { | 478 } else { |
| 479 optype.includeReturnValueSuggestions = true; | 479 // for (^) {} |
| 480 optype.includeTypeNameSuggestions = true; | 480 // for (Str^ str = null;) {} |
| 481 optype.includeVoidReturnSuggestions = true; | 481 // In theory it is possible to specify any expression in initializer, |
| 482 // TODO (danrubel) void return suggestions only belong after | 482 // but for any practical use we need only types. |
| 483 // the 2nd semicolon. Return value suggestions only belong after the | 483 if (entity == node.initialization || entity == node.variables) { |
| 484 // first or second semicolon. | 484 optype.includeTypeNameSuggestions = true; |
| 485 } | |
| 486 // for (; ^) {} | |
| 487 if (entity == node.condition) { | |
| 488 optype.includeTypeNameSuggestions = true; | |
|
Brian Wilkerson
2016/05/10 22:29:08
Seems unlikely to me that we'd want a type in eith
| |
| 489 optype.includeReturnValueSuggestions = true; | |
| 490 } | |
| 491 // for (; ; ^) {} | |
| 492 if (node.updaters.contains(entity)) { | |
| 493 optype.includeTypeNameSuggestions = true; | |
| 494 optype.includeReturnValueSuggestions = true; | |
| 495 optype.includeVoidReturnSuggestions = true; | |
| 496 } | |
| 485 } | 497 } |
| 486 } | 498 } |
| 487 | 499 |
| 488 @override | 500 @override |
| 489 void visitFunctionDeclaration(FunctionDeclaration node) { | 501 void visitFunctionDeclaration(FunctionDeclaration node) { |
| 490 if (identical(entity, node.returnType) || | 502 if (identical(entity, node.returnType) || |
| 491 identical(entity, node.name) && node.returnType == null) { | 503 identical(entity, node.name) && node.returnType == null) { |
| 492 optype.includeTypeNameSuggestions = true; | 504 optype.includeTypeNameSuggestions = true; |
| 493 } | 505 } |
| 494 } | 506 } |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 846 void visitVariableDeclarationStatement(VariableDeclarationStatement node) {} | 858 void visitVariableDeclarationStatement(VariableDeclarationStatement node) {} |
| 847 | 859 |
| 848 @override | 860 @override |
| 849 void visitWhileStatement(WhileStatement node) { | 861 void visitWhileStatement(WhileStatement node) { |
| 850 if (identical(entity, node.condition)) { | 862 if (identical(entity, node.condition)) { |
| 851 optype.includeReturnValueSuggestions = true; | 863 optype.includeReturnValueSuggestions = true; |
| 852 optype.includeTypeNameSuggestions = true; | 864 optype.includeTypeNameSuggestions = true; |
| 853 } | 865 } |
| 854 } | 866 } |
| 855 | 867 |
| 868 bool _isEntityPrevToken(TokenType expectedType) { | |
| 869 Object entity = this.entity; | |
| 870 if (entity is SimpleIdentifier && entity.token.isSynthetic) { | |
| 871 return entity.token.previous.type == expectedType; | |
| 872 } | |
| 873 return false; | |
| 874 } | |
| 875 | |
| 856 bool _isEntityPrevTokenSynthetic() { | 876 bool _isEntityPrevTokenSynthetic() { |
| 857 Object entity = this.entity; | 877 Object entity = this.entity; |
| 858 if (entity is AstNode && entity.beginToken.previous?.isSynthetic ?? false) { | 878 if (entity is AstNode && entity.beginToken.previous?.isSynthetic ?? false) { |
| 859 return true; | 879 return true; |
| 860 } | 880 } |
| 861 return false; | 881 return false; |
| 862 } | 882 } |
| 863 } | 883 } |
| OLD | NEW |