Chromium Code Reviews| Index: pkg/analysis_server/lib/src/services/completion/dart/utilities.dart |
| diff --git a/pkg/analysis_server/lib/src/services/completion/dart/utilities.dart b/pkg/analysis_server/lib/src/services/completion/dart/utilities.dart |
| index 7b888c638f034111c2cf7622d4c10c6e9652259e..28264231126d3498cf11dcd9015e1044d1c9ef26 100644 |
| --- a/pkg/analysis_server/lib/src/services/completion/dart/utilities.dart |
| +++ b/pkg/analysis_server/lib/src/services/completion/dart/utilities.dart |
| @@ -71,26 +71,20 @@ void addDefaultArgDetails( |
| } |
| } |
| - //TODO(pq): generalize and unify with _getDefaultValue |
| if (options?.generateFlutterWidgetChildrenBoilerPlate == true) { |
| if (element is ConstructorElement) { |
| - ConstructorElement constructorElement = element; |
| - ClassElement classElement = constructorElement.enclosingElement; |
| + ClassElement classElement = element.enclosingElement; |
|
danrubel
2017/03/24 13:16:19
It appears that "element" is not modified in this
pquitslund
2017/03/24 15:56:23
Done.
|
| if (isFlutterWidget(classElement)) { |
| - for (ParameterElement param in constructorElement.parameters) { |
| + for (ParameterElement param in element.parameters) { |
| if (param.name == 'children') { |
| - DartType type = param.type; |
| - if (type is InterfaceType && isDartList(type)) { |
| - InterfaceType interfaceType = type; |
| - List<DartType> typeArguments = interfaceType.typeArguments; |
| - if (typeArguments.length == 1) { |
| - if (sb.isNotEmpty) { |
| - sb.write(', '); |
| - } |
| - offset = sb.length; |
| - sb.write('children: <${typeArguments.first.name}>[]'); |
| - } |
| + String defaultValue = getDefaultStringParameterValue(param); |
| + if (sb.isNotEmpty) { |
| + sb.write(', '); |
| } |
| + sb.write('children: '); |
| + offset = sb.length; |
| + sb.write(defaultValue); |
|
Brian Wilkerson
2017/03/23 23:34:48
'defaultValue' can be null here.
pquitslund
2017/03/24 15:56:23
Right. I was thinking this was OK since the `toSt
Brian Wilkerson
2017/03/24 16:04:32
Given a widget class with a constructor of the for
|
| + ranges.addAll([offset, defaultValue.length]); |
| } |
| } |
| } |
| @@ -184,6 +178,23 @@ CompletionSuggestion createLocalSuggestion(SimpleIdentifier id, |
| return suggestion; |
| } |
| +String getDefaultStringParameterValue(ParameterElement param) { |
|
Brian Wilkerson
2017/03/23 23:34:47
Consider passing in a StringSink here rather than
pquitslund
2017/03/24 15:56:23
Interesting idea. As mentioned above, I don't thi
|
| + DartType type = param.type; |
| + if (type is InterfaceType && isDartList(type)) { |
| + List<DartType> typeArguments = type.typeArguments; |
| + StringBuffer sb = new StringBuffer(); |
| + if (typeArguments.length == 1) { |
| + DartType typeArg = typeArguments.first; |
| + if (!typeArg.isDynamic) { |
| + sb.write('<${typeArg.name}>'); |
| + } |
| + sb.write('[]'); |
| + return sb.toString(); |
| + } |
| + } |
| + return null; |
| +} |
| + |
| bool isDartList(DartType type) { |
| ClassElement element = type.element; |
| if (element != null) { |