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

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

Issue 2771123002: Arglist `children:` default value gen fixes. (Closed)
Patch Set: Remove unneeded assignment. 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
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..4f3bb2c64a47c432fe238d5f16f22d574dd71ee7 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,19 @@ void addDefaultArgDetails(
}
}
- //TODO(pq): generalize and unify with _getDefaultValue
if (options?.generateFlutterWidgetChildrenBoilerPlate == true) {
if (element is ConstructorElement) {
- ConstructorElement constructorElement = element;
- ClassElement classElement = constructorElement.enclosingElement;
- if (isFlutterWidget(classElement)) {
- for (ParameterElement param in constructorElement.parameters) {
+ if (isFlutterWidget(element.enclosingElement)) {
+ 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);
+ ranges.addAll([offset, defaultValue.length]);
}
}
}
@@ -184,6 +177,23 @@ CompletionSuggestion createLocalSuggestion(SimpleIdentifier id,
return suggestion;
}
+String getDefaultStringParameterValue(ParameterElement param) {
+ 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) {

Powered by Google App Engine
This is Rietveld 408576698