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

Unified Diff: pkg/analysis_server/lib/src/services/correction/fix_internal.dart

Issue 2707223003: Missing @required arg quick fix improvements. (Closed)
Patch Set: Created 3 years, 10 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/correction/fix_internal.dart
diff --git a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
index eb45caf2cef0f283d9080d42817a773264135a60..6f7687a38aa3feb4c2721c21e8e362e4d494fe31 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
@@ -267,7 +267,8 @@ class FixProcessor {
_addFix_createConstructor_insteadOfSyntheticDefault();
await _addFix_addMissingParameter();
}
- if (errorCode == HintCode.MISSING_REQUIRED_PARAM) {
+ if (errorCode == HintCode.MISSING_REQUIRED_PARAM ||
+ errorCode == HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS) {
_addFix_addMissingRequiredArgument();
}
if (errorCode == StaticWarningCode.FUNCTION_WITHOUT_CALL) {
@@ -572,23 +573,20 @@ class FixProcessor {
}
if (targetElement is ExecutableElement) {
- List<Expression> args = argumentList.arguments;
- List<String> namedArgs = args
- .where((e) => e is NamedExpression)
- .map((e) => (e as NamedExpression).name.label.name)
- .toList(growable: false);
-
- List<ParameterElement> missingParams = targetElement.parameters
- .where((p) => p.isRequired && !namedArgs.contains(p.name))
- .toList(growable: false);
- if (missingParams.isEmpty) {
- return;
+ // Format: "Missing required argument 'foo"
+ List<String> parts = error.message.split("'");
+ if (parts.length < 2) {
+ return; // and error?
Brian Wilkerson 2017/02/22 14:50:04 No error.
}
+ // Grab just the name.
+ String paramName = parts[1];
+
// add proposal
SourceBuilder sb;
+ final List<Expression> args = argumentList.arguments;
if (args.isEmpty) {
sb = new SourceBuilder(file, argumentList.leftParenthesis.end);
} else {
@@ -596,10 +594,11 @@ class FixProcessor {
sb.append(', ');
}
- sb.append(missingParams.map((p) => '${p.name}: null').join(', '));
+ // In the future consider better values than null for specific element types.
+ sb.append('$paramName: null');
_insertBuilder(sb, targetElement);
- _addFix(DartFixKind.ADD_MISSING_REQUIRED_ARGUMENT, []);
+ _addFix(DartFixKind.ADD_MISSING_REQUIRED_ARGUMENT, [paramName]);
}
}
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/fix.dart ('k') | pkg/analysis_server/test/services/correction/fix_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698