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/provisional/completion/dart/completion_targe
t.dart'; | 7 import 'package:analysis_server/src/provisional/completion/dart/completion_targe
t.dart'; |
8 import 'package:analyzer/src/generated/ast.dart'; | 8 import 'package:analyzer/src/generated/ast.dart'; |
9 import 'package:analyzer/src/generated/scanner.dart'; | 9 import 'package:analyzer/src/generated/scanner.dart'; |
10 | 10 |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 } | 318 } |
319 } | 319 } |
320 if (identical(entity, node.iterable)) { | 320 if (identical(entity, node.iterable)) { |
321 optype.includeReturnValueSuggestions = true; | 321 optype.includeReturnValueSuggestions = true; |
322 optype.includeTypeNameSuggestions = true; | 322 optype.includeTypeNameSuggestions = true; |
323 } | 323 } |
324 } | 324 } |
325 | 325 |
326 @override | 326 @override |
327 void visitFormalParameterList(FormalParameterList node) { | 327 void visitFormalParameterList(FormalParameterList node) { |
328 optype.includeTypeNameSuggestions = true; | 328 dynamic entity = this.entity; |
| 329 if (entity is Token && entity.previous != null) { |
| 330 TokenType type = entity.previous.type; |
| 331 if (type == TokenType.OPEN_PAREN || type == TokenType.COMMA) { |
| 332 optype.includeTypeNameSuggestions = true; |
| 333 } |
| 334 } |
| 335 // Handle default normal parameter just as a normal parameter. |
| 336 if (entity is DefaultFormalParameter) { |
| 337 entity = entity.parameter; |
| 338 } |
| 339 // "(^ this.field)" |
| 340 if (entity is FieldFormalParameter) { |
| 341 if (offset < entity.thisKeyword.offset) { |
| 342 optype.includeTypeNameSuggestions = true; |
| 343 } |
| 344 } |
| 345 // "(Type name)" |
| 346 if (entity is SimpleFormalParameter) { |
| 347 // "(Type^)" is parsed as a parameter with the _name_ "Type". |
| 348 if (entity.type == null) { |
| 349 optype.includeTypeNameSuggestions = true; |
| 350 } |
| 351 // If inside of "Type" in "(Type^ name)", then include types. |
| 352 if (entity.type != null && |
| 353 entity.type.offset <= offset && |
| 354 offset <= entity.type.end) { |
| 355 optype.includeTypeNameSuggestions = true; |
| 356 } |
| 357 } |
329 } | 358 } |
330 | 359 |
331 @override | 360 @override |
332 void visitForStatement(ForStatement node) { | 361 void visitForStatement(ForStatement node) { |
333 optype.includeReturnValueSuggestions = true; | 362 optype.includeReturnValueSuggestions = true; |
334 optype.includeTypeNameSuggestions = true; | 363 optype.includeTypeNameSuggestions = true; |
335 optype.includeVoidReturnSuggestions = true; | 364 optype.includeVoidReturnSuggestions = true; |
336 // TODO (danrubel) void return suggestions only belong after | 365 // TODO (danrubel) void return suggestions only belong after |
337 // the 2nd semicolon. Return value suggestions only belong after the | 366 // the 2nd semicolon. Return value suggestions only belong after the |
338 // e1st or second semicolon. | 367 // e1st or second semicolon. |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 } | 482 } |
454 } | 483 } |
455 | 484 |
456 @override | 485 @override |
457 void visitNode(AstNode node) { | 486 void visitNode(AstNode node) { |
458 // no suggestion by default | 487 // no suggestion by default |
459 } | 488 } |
460 | 489 |
461 @override | 490 @override |
462 void visitNormalFormalParameter(NormalFormalParameter node) { | 491 void visitNormalFormalParameter(NormalFormalParameter node) { |
463 optype.includeReturnValueSuggestions = true; | 492 if (node.identifier != entity) { |
464 optype.includeTypeNameSuggestions = true; | 493 optype.includeReturnValueSuggestions = true; |
| 494 optype.includeTypeNameSuggestions = true; |
| 495 } |
465 } | 496 } |
466 | 497 |
467 void visitParenthesizedExpression(ParenthesizedExpression node) { | 498 void visitParenthesizedExpression(ParenthesizedExpression node) { |
468 if (identical(entity, node.expression)) { | 499 if (identical(entity, node.expression)) { |
469 optype.includeReturnValueSuggestions = true; | 500 optype.includeReturnValueSuggestions = true; |
470 optype.includeTypeNameSuggestions = true; | 501 optype.includeTypeNameSuggestions = true; |
471 } | 502 } |
472 } | 503 } |
473 | 504 |
474 @override | 505 @override |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 void visitVariableDeclarationStatement(VariableDeclarationStatement node) {} | 672 void visitVariableDeclarationStatement(VariableDeclarationStatement node) {} |
642 | 673 |
643 @override | 674 @override |
644 void visitWhileStatement(WhileStatement node) { | 675 void visitWhileStatement(WhileStatement node) { |
645 if (identical(entity, node.condition)) { | 676 if (identical(entity, node.condition)) { |
646 optype.includeReturnValueSuggestions = true; | 677 optype.includeReturnValueSuggestions = true; |
647 optype.includeTypeNameSuggestions = true; | 678 optype.includeTypeNameSuggestions = true; |
648 } | 679 } |
649 } | 680 } |
650 } | 681 } |
OLD | NEW |