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/ide_options.dart'; | 10 import 'package:analysis_server/src/ide_options.dart'; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 73 |
74 //TODO(pq): generalize and unify with _getDefaultValue | 74 //TODO(pq): generalize and unify with _getDefaultValue |
75 if (options?.generateFlutterWidgetChildrenBoilerPlate == true) { | 75 if (options?.generateFlutterWidgetChildrenBoilerPlate == true) { |
76 if (element is ConstructorElement) { | 76 if (element is ConstructorElement) { |
77 ConstructorElement constructorElement = element; | 77 ConstructorElement constructorElement = element; |
78 ClassElement classElement = constructorElement.enclosingElement; | 78 ClassElement classElement = constructorElement.enclosingElement; |
79 if (isFlutterWidget(classElement)) { | 79 if (isFlutterWidget(classElement)) { |
80 for (ParameterElement param in constructorElement.parameters) { | 80 for (ParameterElement param in constructorElement.parameters) { |
81 if (param.name == 'children') { | 81 if (param.name == 'children') { |
82 DartType type = param.type; | 82 DartType type = param.type; |
83 if (type is InterfaceType && _isDartList(type)) { | 83 if (type is InterfaceType && isDartList(type)) { |
84 InterfaceType interfaceType = type; | 84 InterfaceType interfaceType = type; |
85 List<DartType> typeArguments = interfaceType.typeArguments; | 85 List<DartType> typeArguments = interfaceType.typeArguments; |
86 if (typeArguments.length == 1) { | 86 if (typeArguments.length == 1) { |
87 if (sb.isNotEmpty) { | 87 if (sb.isNotEmpty) { |
88 sb.write(', '); | 88 sb.write(', '); |
89 } | 89 } |
90 offset = sb.length; | 90 offset = sb.length; |
91 sb.write('children: <${typeArguments.first.name}>[]'); | 91 sb.write('children: <${typeArguments.first.name}>[]'); |
92 } | 92 } |
93 } | 93 } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 if (classId != null) { | 177 if (classId != null) { |
178 String className = classId.name; | 178 String className = classId.name; |
179 if (className != null && className.length > 0) { | 179 if (className != null && className.length > 0) { |
180 suggestion.declaringType = className; | 180 suggestion.declaringType = className; |
181 } | 181 } |
182 } | 182 } |
183 } | 183 } |
184 return suggestion; | 184 return suggestion; |
185 } | 185 } |
186 | 186 |
| 187 bool isDartList(DartType type) { |
| 188 ClassElement element = type.element; |
| 189 if (element != null) { |
| 190 return element.name == "List" && element.library.isDartCore; |
| 191 } |
| 192 return false; |
| 193 } |
| 194 |
187 /** | 195 /** |
188 * Return `true` if the @deprecated annotation is present on the given [node]. | 196 * Return `true` if the @deprecated annotation is present on the given [node]. |
189 */ | 197 */ |
190 bool isDeprecated(AnnotatedNode node) { | 198 bool isDeprecated(AnnotatedNode node) { |
191 if (node != null) { | 199 if (node != null) { |
192 NodeList<Annotation> metadata = node.metadata; | 200 NodeList<Annotation> metadata = node.metadata; |
193 if (metadata != null) { | 201 if (metadata != null) { |
194 return metadata.any((Annotation a) { | 202 return metadata.any((Annotation a) { |
195 return a.name is SimpleIdentifier && a.name.name == 'deprecated'; | 203 return a.name is SimpleIdentifier && a.name.name == 'deprecated'; |
196 }); | 204 }); |
(...skipping 26 matching lines...) Expand all Loading... |
223 //TODO (danrubel) include type arguments | 231 //TODO (danrubel) include type arguments |
224 } | 232 } |
225 return name; | 233 return name; |
226 } else if (type is GenericFunctionType) { | 234 } else if (type is GenericFunctionType) { |
227 // TODO(brianwilkerson) Implement this. | 235 // TODO(brianwilkerson) Implement this. |
228 } | 236 } |
229 return DYNAMIC; | 237 return DYNAMIC; |
230 } | 238 } |
231 | 239 |
232 String _getDefaultValue(ParameterElement param) => 'null'; | 240 String _getDefaultValue(ParameterElement param) => 'null'; |
233 | |
234 bool _isDartList(DartType type) { | |
235 ClassElement element = type.element; | |
236 if (element != null) { | |
237 return element.name == "List" && element.library.isDartCore; | |
238 } | |
239 return false; | |
240 } | |
OLD | NEW |