Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: pkg/analysis_server/lib/src/services/completion/suggestion_builder.dart

Issue 1260593005: update suggestion element return type to have type param (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.suggestion.builder; 5 library services.completion.suggestion.builder;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analysis_server/src/protocol_server.dart' as protocol; 10 import 'package:analysis_server/src/protocol_server.dart' as protocol;
(...skipping 10 matching lines...) Expand all
21 21
22 /** 22 /**
23 * Return a suggestion based upon the given element 23 * Return a suggestion based upon the given element
24 * or `null` if a suggestion is not appropriate for the given element. 24 * or `null` if a suggestion is not appropriate for the given element.
25 * If the suggestion is not currently in scope, then specify 25 * If the suggestion is not currently in scope, then specify
26 * importForSource as the source to which an import should be added. 26 * importForSource as the source to which an import should be added.
27 */ 27 */
28 CompletionSuggestion createSuggestion(Element element, 28 CompletionSuggestion createSuggestion(Element element,
29 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, 29 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION,
30 int relevance: DART_RELEVANCE_DEFAULT, Source importForSource}) { 30 int relevance: DART_RELEVANCE_DEFAULT, Source importForSource}) {
31 String nameForType(DartType type) { 31 if (element is ExecutableElement && element.isOperator) {
32 if (type == null) { 32 // Do not include operators in suggestions
33 return DYNAMIC; 33 return null;
34 }
35 String name = type.displayName;
36 if (name == null || name.length <= 0) {
37 return DYNAMIC;
38 }
39 //TODO (danrubel) include type arguments ??
40 return name;
41 } 34 }
42
43 String returnType = null;
44 if (element is ExecutableElement) {
45 if (element.isOperator) {
46 // Do not include operators in suggestions
47 return null;
48 }
49 if (element is PropertyAccessorElement && element.isSetter) {
50 // no return type
51 } else {
52 returnType = nameForType(element.returnType);
53 }
54 } else if (element is VariableElement) {
55 returnType = nameForType(element.type);
56 } else if (element is FunctionTypeAliasElement) {
57 returnType = nameForType(element.returnType);
58 }
59
60 String completion = element.displayName; 35 String completion = element.displayName;
61 bool isDeprecated = element.isDeprecated; 36 bool isDeprecated = element.isDeprecated;
62 CompletionSuggestion suggestion = new CompletionSuggestion(kind, 37 CompletionSuggestion suggestion = new CompletionSuggestion(kind,
63 isDeprecated ? DART_RELEVANCE_LOW : relevance, completion, 38 isDeprecated ? DART_RELEVANCE_LOW : relevance, completion,
64 completion.length, 0, isDeprecated, false); 39 completion.length, 0, isDeprecated, false);
65 suggestion.element = protocol.newElement_fromEngine(element); 40 suggestion.element = protocol.newElement_fromEngine(element);
66 Element enclosingElement = element.enclosingElement; 41 Element enclosingElement = element.enclosingElement;
67 if (enclosingElement is ClassElement) { 42 if (enclosingElement is ClassElement) {
68 suggestion.declaringType = enclosingElement.displayName; 43 suggestion.declaringType = enclosingElement.displayName;
69 } 44 }
70 suggestion.returnType = returnType; 45 suggestion.returnType = getReturnTypeString(element);
71 if (element is ExecutableElement && element is! PropertyAccessorElement) { 46 if (element is ExecutableElement && element is! PropertyAccessorElement) {
72 suggestion.parameterNames = element.parameters 47 suggestion.parameterNames = element.parameters
73 .map((ParameterElement parameter) => parameter.name) 48 .map((ParameterElement parameter) => parameter.name)
74 .toList(); 49 .toList();
75 suggestion.parameterTypes = element.parameters 50 suggestion.parameterTypes = element.parameters
76 .map((ParameterElement parameter) => parameter.type.displayName) 51 .map((ParameterElement parameter) => parameter.type.displayName)
77 .toList(); 52 .toList();
78 suggestion.requiredParameterCount = element.parameters.where( 53 suggestion.requiredParameterCount = element.parameters.where(
79 (ParameterElement parameter) => 54 (ParameterElement parameter) =>
80 parameter.parameterKind == ParameterKind.REQUIRED).length; 55 parameter.parameterKind == ParameterKind.REQUIRED).length;
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 * or `false` if [computeFull] should be called. 625 * or `false` if [computeFull] should be called.
651 */ 626 */
652 bool computeFast(AstNode node); 627 bool computeFast(AstNode node);
653 628
654 /** 629 /**
655 * Return a future that computes the suggestions given a fully resolved AST. 630 * Return a future that computes the suggestions given a fully resolved AST.
656 * The future returns `true` if suggestions were added, else `false`. 631 * The future returns `true` if suggestions were added, else `false`.
657 */ 632 */
658 Future<bool> computeFull(AstNode node); 633 Future<bool> computeFull(AstNode node);
659 } 634 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698