OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 /** | 5 /** |
6 * A collection of utility methods used by completion contributors. | 6 * A collection of utility methods used by completion contributors. |
7 */ | 7 */ |
8 import 'package:analysis_server/plugin/protocol/protocol.dart' as protocol | 8 import 'package:analysis_server/plugin/protocol/protocol.dart' as protocol |
9 show Element, ElementKind; | 9 show Element, ElementKind; |
10 import 'package:analysis_server/src/protocol_server.dart' | 10 import 'package:analysis_server/src/protocol_server.dart' |
11 show CompletionSuggestion, CompletionSuggestionKind, Location; | 11 show CompletionSuggestion, CompletionSuggestionKind, Location; |
12 import 'package:analysis_server/src/provisional/completion/dart/completion_dart.
dart'; | 12 import 'package:analysis_server/src/provisional/completion/dart/completion_dart.
dart'; |
13 import 'package:analyzer/dart/ast/ast.dart'; | 13 import 'package:analyzer/dart/ast/ast.dart'; |
14 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; | 14 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; |
15 import 'package:analyzer/dart/ast/token.dart'; | 15 import 'package:analyzer/dart/ast/token.dart'; |
| 16 import 'package:analyzer/dart/element/element.dart'; |
16 import 'package:analyzer/src/dart/ast/token.dart'; | 17 import 'package:analyzer/src/dart/ast/token.dart'; |
17 import 'package:analyzer/src/generated/source.dart'; | 18 import 'package:analyzer/src/generated/source.dart'; |
18 | 19 |
19 /** | 20 /** |
20 * The name of the type `dynamic`; | 21 * The name of the type `dynamic`; |
21 */ | 22 */ |
22 const DYNAMIC = 'dynamic'; | 23 const DYNAMIC = 'dynamic'; |
23 | 24 |
24 /** | 25 /** |
25 * A marker used in place of `null` when a function has no return type. | 26 * A marker used in place of `null` when a function has no return type. |
26 */ | 27 */ |
27 final TypeName NO_RETURN_TYPE = astFactory.typeName( | 28 final TypeName NO_RETURN_TYPE = astFactory.typeName( |
28 astFactory.simpleIdentifier(new StringToken(TokenType.IDENTIFIER, '', 0)), | 29 astFactory.simpleIdentifier(new StringToken(TokenType.IDENTIFIER, '', 0)), |
29 null); | 30 null); |
30 | 31 |
31 /** | 32 /** |
| 33 * Build a default argument list based on the given [requiredParams] and |
| 34 * [namedParams]. |
| 35 */ |
| 36 String buildDefaultArgList(Iterable<ParameterElement> requiredParams, |
| 37 Iterable<ParameterElement> namedParams) { |
| 38 List<String> args = requiredParams.map((p) => p.name).toList(); |
| 39 List<String> requiredArgs = namedParams |
| 40 .where((p) => p.isRequired) |
| 41 .map((p) => '${p.name}: null') |
| 42 .toList(); |
| 43 args.addAll(requiredArgs); |
| 44 return args.isEmpty ? null : args.join(', '); |
| 45 } |
| 46 |
| 47 /** |
32 * Create a new protocol Element for inclusion in a completion suggestion. | 48 * Create a new protocol Element for inclusion in a completion suggestion. |
33 */ | 49 */ |
34 protocol.Element createLocalElement( | 50 protocol.Element createLocalElement( |
35 Source source, protocol.ElementKind kind, SimpleIdentifier id, | 51 Source source, protocol.ElementKind kind, SimpleIdentifier id, |
36 {String parameters, | 52 {String parameters, |
37 TypeAnnotation returnType, | 53 TypeAnnotation returnType, |
38 bool isAbstract: false, | 54 bool isAbstract: false, |
39 bool isDeprecated: false}) { | 55 bool isDeprecated: false}) { |
40 String name; | 56 String name; |
41 Location location; | 57 Location location; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 TypeArgumentList typeArgs = type.typeArguments; | 164 TypeArgumentList typeArgs = type.typeArguments; |
149 if (typeArgs != null) { | 165 if (typeArgs != null) { |
150 //TODO (danrubel) include type arguments | 166 //TODO (danrubel) include type arguments |
151 } | 167 } |
152 return name; | 168 return name; |
153 } else if (type is GenericFunctionType) { | 169 } else if (type is GenericFunctionType) { |
154 // TODO(brianwilkerson) Implement this. | 170 // TODO(brianwilkerson) Implement this. |
155 } | 171 } |
156 return DYNAMIC; | 172 return DYNAMIC; |
157 } | 173 } |
OLD | NEW |