Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Unified Diff: pkg/analysis_server/lib/src/services/completion/dart/arglist_contributor.dart

Issue 2768273003: <Widget> boilerplate for Flutter `children:` suggestions. (Closed)
Patch Set: format Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/completion/dart/utilities.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/services/completion/dart/arglist_contributor.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/arglist_contributor.dart b/pkg/analysis_server/lib/src/services/completion/dart/arglist_contributor.dart
index 0e92c36c30f961861a8980265ccefed327bd7225..872051ee9d40e24343a78803ab5b7acb702f941f 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/arglist_contributor.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/arglist_contributor.dart
@@ -6,12 +6,16 @@ library services.completion.contributor.dart.arglist;
import 'dart:async';
+import 'package:analysis_server/src/ide_options.dart';
import 'package:analysis_server/src/protocol_server.dart'
hide Element, ElementKind;
import 'package:analysis_server/src/provisional/completion/dart/completion_dart.dart';
+import 'package:analysis_server/src/services/completion/dart/utilities.dart';
+import 'package:analysis_server/src/services/correction/flutter_util.dart';
import 'package:analysis_server/src/utilities/documentation.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
+import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/src/generated/utilities_dart.dart';
/**
@@ -265,10 +269,53 @@ class ArgListContributor extends DartCompletionContributor {
_setDocumentation(suggestion, parameter.field?.documentationComment);
suggestion.element = convertElement(parameter);
}
+
+ String defaultValue = _getDefaultValue(parameter, request.ideOptions);
+ if (defaultValue != null) {
+ //TODO(pq): unify with `utilities.dart`
Brian Wilkerson 2017/03/23 20:27:53 Do these TODOs still apply?
pquitslund 2017/03/23 22:15:16 They may. There's a bit of duplication I want to
+ StringBuffer sb = new StringBuffer();
+ sb.write('${parameter.name}: ');
+ int offset = sb.length;
+ sb.write(defaultValue);
+ suggestion.defaultArgumentListString = defaultValue;
+ suggestion.defaultArgumentListTextRanges = [
+ offset,
+ defaultValue.length
+ ];
+ }
+
suggestions.add(suggestion);
}
}
+ //TODO(pq): move and unify w/ `utilities.dart`
+ String _getDefaultValue(ParameterElement param, IdeOptions options) {
+ if (options?.generateFlutterWidgetChildrenBoilerPlate == true) {
+ Element element = param.enclosingElement;
+ if (element is ConstructorElement) {
+ ClassElement classElement = element.enclosingElement;
+ if (isFlutterWidget(classElement)) {
+ if (param.name == 'children') {
+ 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;
+ }
+
void _addSuggestions(Iterable<ParameterElement> parameters) {
if (parameters == null || parameters.length == 0) {
return;
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/completion/dart/utilities.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698