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 80002537ba2f696601afd7b98ca51cd537c446f8..6d8ce556bafc0b38ca84bb683a8133456d88ebee 100644 |
| --- a/pkg/analysis_server/lib/src/services/completion/dart/utilities.dart |
| +++ b/pkg/analysis_server/lib/src/services/completion/dart/utilities.dart |
| @@ -7,13 +7,16 @@ |
| */ |
| import 'package:analysis_server/plugin/protocol/protocol.dart' as protocol |
| show Element, ElementKind; |
| +import 'package:analysis_server/src/ide_options.dart'; |
| import 'package:analysis_server/src/protocol_server.dart' |
| show CompletionSuggestion, CompletionSuggestionKind, Location; |
| import 'package:analysis_server/src/provisional/completion/dart/completion_dart.dart'; |
| +import 'package:analysis_server/src/services/correction/flutter_util.dart'; |
| import 'package:analyzer/dart/ast/ast.dart'; |
| import 'package:analyzer/dart/ast/standard_ast_factory.dart'; |
| import 'package:analyzer/dart/ast/token.dart'; |
| import 'package:analyzer/dart/element/element.dart'; |
| +import 'package:analyzer/dart/element/type.dart'; |
| import 'package:analyzer/src/dart/ast/token.dart'; |
| import 'package:analyzer/src/generated/source.dart'; |
| @@ -35,8 +38,10 @@ final TypeName NO_RETURN_TYPE = astFactory.typeName( |
| */ |
| void addDefaultArgDetails( |
| CompletionSuggestion suggestion, |
| + Element element, |
| Iterable<ParameterElement> requiredParams, |
| - Iterable<ParameterElement> namedParams) { |
| + Iterable<ParameterElement> namedParams, |
| + IdeOptions options) { |
| StringBuffer sb = new StringBuffer(); |
| List<int> ranges = <int>[]; |
| @@ -66,6 +71,32 @@ void addDefaultArgDetails( |
| } |
| } |
| + //TODO(pq): generalize and unify with _getDefaultValue |
| + if (options?.generateFlutterWidgetChildrenBoilerPlate == true) { |
|
Brian Wilkerson
2017/03/22 22:05:46
I think I'd just make it mandatory to pass in a no
|
| + if (element is ConstructorElement) { |
| + ConstructorElement constructorElement = element; |
| + ClassElement classElement = constructorElement.enclosingElement; |
| + if (isFlutterWidget(classElement)) { |
| + for (ParameterElement param in constructorElement.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}>[]'); |
| + } |
| + } |
| + } |
| + } |
| + } |
| + } |
| + } |
| + |
| suggestion.defaultArgumentListString = sb.isNotEmpty ? sb.toString() : null; |
| suggestion.defaultArgumentListTextRanges = ranges.isNotEmpty ? ranges : null; |
| } |
| @@ -199,3 +230,11 @@ String nameForType(TypeAnnotation type) { |
| } |
| String _getDefaultValue(ParameterElement param) => 'null'; |
| + |
| +bool _isDartList(DartType type) { |
| + ClassElement element = type.element; |
| + if (element != null) { |
| + return element.name == "List" && element.library.isDartCore; |
| + } |
| + return false; |
| +} |