OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.suggestion.builder; | 5 library services.completion.dart.suggestion.builder; |
6 | 6 |
7 import 'package:analysis_server/src/protocol_server.dart' as protocol; | 7 import 'package:analysis_server/src/protocol_server.dart' as protocol; |
8 import 'package:analysis_server/src/protocol_server.dart' | 8 import 'package:analysis_server/src/protocol_server.dart' |
9 hide Element, ElementKind; | 9 hide Element, ElementKind; |
10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 suggestion.element = protocol.convertElement(element); | 45 suggestion.element = protocol.convertElement(element); |
46 Element enclosingElement = element.enclosingElement; | 46 Element enclosingElement = element.enclosingElement; |
47 if (enclosingElement is ClassElement) { | 47 if (enclosingElement is ClassElement) { |
48 suggestion.declaringType = enclosingElement.displayName; | 48 suggestion.declaringType = enclosingElement.displayName; |
49 } | 49 } |
50 suggestion.returnType = getReturnTypeString(element); | 50 suggestion.returnType = getReturnTypeString(element); |
51 if (element is ExecutableElement && element is! PropertyAccessorElement) { | 51 if (element is ExecutableElement && element is! PropertyAccessorElement) { |
52 suggestion.parameterNames = element.parameters | 52 suggestion.parameterNames = element.parameters |
53 .map((ParameterElement parameter) => parameter.name) | 53 .map((ParameterElement parameter) => parameter.name) |
54 .toList(); | 54 .toList(); |
55 suggestion.parameterTypes = element.parameters | 55 suggestion.parameterTypes = |
56 .map((ParameterElement parameter) => parameter.type.displayName) | 56 element.parameters.map((ParameterElement parameter) { |
57 .toList(); | 57 DartType paramType = parameter.type; |
| 58 // Gracefully degrade if type not resolved yet |
| 59 return paramType != null ? paramType.displayName : 'var'; |
| 60 }).toList(); |
58 suggestion.requiredParameterCount = element.parameters | 61 suggestion.requiredParameterCount = element.parameters |
59 .where((ParameterElement parameter) => | 62 .where((ParameterElement parameter) => |
60 parameter.parameterKind == ParameterKind.REQUIRED) | 63 parameter.parameterKind == ParameterKind.REQUIRED) |
61 .length; | 64 .length; |
62 suggestion.hasNamedParameters = element.parameters.any( | 65 suggestion.hasNamedParameters = element.parameters.any( |
63 (ParameterElement parameter) => | 66 (ParameterElement parameter) => |
64 parameter.parameterKind == ParameterKind.NAMED); | 67 parameter.parameterKind == ParameterKind.NAMED); |
65 } | 68 } |
66 if (importForSource != null) { | 69 if (importForSource != null) { |
67 String srcPath = path.dirname(importForSource.fullName); | 70 String srcPath = path.dirname(importForSource.fullName); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 CompletionSuggestionKind kind, | 253 CompletionSuggestionKind kind, |
251 LibraryElement library, | 254 LibraryElement library, |
252 bool typesOnly, | 255 bool typesOnly, |
253 bool instCreation) { | 256 bool instCreation) { |
254 if (library != null) { | 257 if (library != null) { |
255 library.visitChildren(new LibraryElementSuggestionBuilder( | 258 library.visitChildren(new LibraryElementSuggestionBuilder( |
256 request, kind, typesOnly, instCreation)); | 259 request, kind, typesOnly, instCreation)); |
257 } | 260 } |
258 } | 261 } |
259 } | 262 } |
OLD | NEW |