| 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.local; | 5 library services.completion.computer.dart.local; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | |
| 9 | 8 |
| 10 import 'package:analysis_server/src/protocol.dart' as protocol | 9 import 'package:analysis_server/src/protocol.dart' as protocol |
| 11 show Element, ElementKind; | 10 show Element, ElementKind; |
| 12 import 'package:analysis_server/src/protocol.dart' hide Element, ElementKind; | 11 import 'package:analysis_server/src/protocol.dart' hide Element, ElementKind; |
| 13 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; | 12 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; |
| 14 import 'package:analysis_server/src/services/completion/local_declaration_visito
r.dart'; | 13 import 'package:analysis_server/src/services/completion/local_declaration_visito
r.dart'; |
| 15 import 'package:analysis_server/src/services/completion/optype.dart'; | 14 import 'package:analysis_server/src/services/completion/optype.dart'; |
| 16 import 'package:analyzer/src/generated/ast.dart'; | 15 import 'package:analyzer/src/generated/ast.dart'; |
| 17 import 'package:analyzer/src/generated/scanner.dart'; | 16 import 'package:analyzer/src/generated/scanner.dart'; |
| 18 import 'package:analyzer/src/generated/utilities_dart.dart'; | 17 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 CompletionSuggestion suggestion = new CompletionSuggestion( | 265 CompletionSuggestion suggestion = new CompletionSuggestion( |
| 267 CompletionSuggestionKind.INVOCATION, | 266 CompletionSuggestionKind.INVOCATION, |
| 268 isDeprecated ? DART_RELEVANCE_LOW : DART_RELEVANCE_DEFAULT, completion, | 267 isDeprecated ? DART_RELEVANCE_LOW : DART_RELEVANCE_DEFAULT, completion, |
| 269 completion.length, 0, isDeprecated, false, | 268 completion.length, 0, isDeprecated, false, |
| 270 declaringType: classDecl.name.name, | 269 declaringType: classDecl.name.name, |
| 271 element: element, | 270 element: element, |
| 272 parameterNames: parameterNames, | 271 parameterNames: parameterNames, |
| 273 parameterTypes: parameterTypes, | 272 parameterTypes: parameterTypes, |
| 274 requiredParameterCount: requiredParameterCount, | 273 requiredParameterCount: requiredParameterCount, |
| 275 hasNamedParameters: hasNamedParameters); | 274 hasNamedParameters: hasNamedParameters); |
| 276 request.suggestions.add(suggestion); | 275 request.addSuggestion(suggestion); |
| 277 return suggestion; | 276 return suggestion; |
| 278 } | 277 } |
| 279 | 278 |
| 280 /** | 279 /** |
| 281 * Determine the name of the type for the given constructor parameter. | 280 * Determine the name of the type for the given constructor parameter. |
| 282 */ | 281 */ |
| 283 String _nameForParamType(NormalFormalParameter param) { | 282 String _nameForParamType(NormalFormalParameter param) { |
| 284 if (param is SimpleFormalParameter) { | 283 if (param is SimpleFormalParameter) { |
| 285 return _nameForType(param.type); | 284 return _nameForType(param.type); |
| 286 } | 285 } |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 finished(); | 395 finished(); |
| 397 } | 396 } |
| 398 | 397 |
| 399 CompletionSuggestion _addSuggestion(SimpleIdentifier id) { | 398 CompletionSuggestion _addSuggestion(SimpleIdentifier id) { |
| 400 if (id != null) { | 399 if (id != null) { |
| 401 String completion = id.name; | 400 String completion = id.name; |
| 402 if (completion != null && completion.length > 0 && completion != '_') { | 401 if (completion != null && completion.length > 0 && completion != '_') { |
| 403 CompletionSuggestion suggestion = new CompletionSuggestion( | 402 CompletionSuggestion suggestion = new CompletionSuggestion( |
| 404 CompletionSuggestionKind.IDENTIFIER, DART_RELEVANCE_DEFAULT, | 403 CompletionSuggestionKind.IDENTIFIER, DART_RELEVANCE_DEFAULT, |
| 405 completion, completion.length, 0, false, false); | 404 completion, completion.length, 0, false, false); |
| 406 request.suggestions.add(suggestion); | 405 request.addSuggestion(suggestion); |
| 407 return suggestion; | 406 return suggestion; |
| 408 } | 407 } |
| 409 } | 408 } |
| 410 return null; | 409 return null; |
| 411 } | 410 } |
| 412 | 411 |
| 413 /** | 412 /** |
| 414 * Create a new protocol Element for inclusion in a completion suggestion. | 413 * Create a new protocol Element for inclusion in a completion suggestion. |
| 415 */ | 414 */ |
| 416 protocol.Element _createElement( | 415 protocol.Element _createElement( |
| 417 protocol.ElementKind kind, SimpleIdentifier id) { | 416 protocol.ElementKind kind, SimpleIdentifier id) { |
| 418 String name = id.name; | 417 String name = id.name; |
| 419 int flags = | 418 int flags = |
| 420 protocol.Element.makeFlags(isPrivate: Identifier.isPrivateName(name)); | 419 protocol.Element.makeFlags(isPrivate: Identifier.isPrivateName(name)); |
| 421 return new protocol.Element(kind, name, flags); | 420 return new protocol.Element(kind, name, flags); |
| 422 } | 421 } |
| 423 } | 422 } |
| 424 | 423 |
| 425 /** | 424 /** |
| 426 * A visitor for collecting suggestions from the most specific child [AstNode] | 425 * A visitor for collecting suggestions from the most specific child [AstNode] |
| 427 * that contains the completion offset to the [CompilationUnit]. | 426 * that contains the completion offset to the [CompilationUnit]. |
| 428 */ | 427 */ |
| 429 class _LocalVisitor extends LocalDeclarationVisitor { | 428 class _LocalVisitor extends LocalDeclarationVisitor { |
| 430 final DartCompletionRequest request; | 429 final DartCompletionRequest request; |
| 431 final OpType optype; | 430 final OpType optype; |
| 432 HashSet<String> completions = new HashSet(); | |
| 433 | 431 |
| 434 _LocalVisitor(this.request, int offset, this.optype) : super(offset); | 432 _LocalVisitor(this.request, int offset, this.optype) : super(offset); |
| 435 | 433 |
| 436 @override | 434 @override |
| 437 void declaredClass(ClassDeclaration declaration) { | 435 void declaredClass(ClassDeclaration declaration) { |
| 438 if (optype.includeTypeNameSuggestions) { | 436 if (optype.includeTypeNameSuggestions) { |
| 439 bool isDeprecated = _isDeprecated(declaration); | 437 bool isDeprecated = _isDeprecated(declaration); |
| 440 CompletionSuggestion suggestion = _addSuggestion(declaration.name, | 438 CompletionSuggestion suggestion = _addSuggestion(declaration.name, |
| 441 _NO_RETURN_TYPE, isDeprecated, DART_RELEVANCE_DEFAULT); | 439 _NO_RETURN_TYPE, isDeprecated, DART_RELEVANCE_DEFAULT); |
| 442 if (suggestion != null) { | 440 if (suggestion != null) { |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 suggestion.requiredParameterCount = paramList.where( | 659 suggestion.requiredParameterCount = paramList.where( |
| 662 (FormalParameter param) => param is! DefaultFormalParameter).length; | 660 (FormalParameter param) => param is! DefaultFormalParameter).length; |
| 663 suggestion.hasNamedParameters = paramList | 661 suggestion.hasNamedParameters = paramList |
| 664 .any((FormalParameter param) => param.kind == ParameterKind.NAMED); | 662 .any((FormalParameter param) => param.kind == ParameterKind.NAMED); |
| 665 } | 663 } |
| 666 | 664 |
| 667 CompletionSuggestion _addSuggestion(SimpleIdentifier id, TypeName returnType, | 665 CompletionSuggestion _addSuggestion(SimpleIdentifier id, TypeName returnType, |
| 668 bool isDeprecated, int defaultRelevance, {ClassDeclaration classDecl}) { | 666 bool isDeprecated, int defaultRelevance, {ClassDeclaration classDecl}) { |
| 669 if (id != null) { | 667 if (id != null) { |
| 670 String completion = id.name; | 668 String completion = id.name; |
| 671 if (completion != null && | 669 if (completion != null && completion.length > 0 && completion != '_') { |
| 672 completion.length > 0 && | |
| 673 completion != '_' && | |
| 674 completions.add(completion)) { | |
| 675 CompletionSuggestion suggestion = new CompletionSuggestion( | 670 CompletionSuggestion suggestion = new CompletionSuggestion( |
| 676 CompletionSuggestionKind.INVOCATION, | 671 CompletionSuggestionKind.INVOCATION, |
| 677 isDeprecated ? DART_RELEVANCE_LOW : defaultRelevance, completion, | 672 isDeprecated ? DART_RELEVANCE_LOW : defaultRelevance, completion, |
| 678 completion.length, 0, isDeprecated, false, | 673 completion.length, 0, isDeprecated, false, |
| 679 returnType: _nameForType(returnType)); | 674 returnType: _nameForType(returnType)); |
| 680 if (classDecl != null) { | 675 if (classDecl != null) { |
| 681 SimpleIdentifier identifier = classDecl.name; | 676 SimpleIdentifier identifier = classDecl.name; |
| 682 if (identifier != null) { | 677 if (identifier != null) { |
| 683 String name = identifier.name; | 678 String name = identifier.name; |
| 684 if (name != null && name.length > 0) { | 679 if (name != null && name.length > 0) { |
| 685 suggestion.declaringType = name; | 680 suggestion.declaringType = name; |
| 686 } | 681 } |
| 687 } | 682 } |
| 688 } | 683 } |
| 689 request.suggestions.add(suggestion); | 684 request.addSuggestion(suggestion); |
| 690 return suggestion; | 685 return suggestion; |
| 691 } | 686 } |
| 692 } | 687 } |
| 693 return null; | 688 return null; |
| 694 } | 689 } |
| 695 | 690 |
| 696 bool _isVoid(TypeName returnType) { | 691 bool _isVoid(TypeName returnType) { |
| 697 if (returnType != null) { | 692 if (returnType != null) { |
| 698 Identifier id = returnType.name; | 693 Identifier id = returnType.name; |
| 699 if (id != null && id.name == 'void') { | 694 if (id != null && id.name == 'void') { |
| 700 return true; | 695 return true; |
| 701 } | 696 } |
| 702 } | 697 } |
| 703 return false; | 698 return false; |
| 704 } | 699 } |
| 705 } | 700 } |
| OLD | NEW |