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

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

Issue 2753123003: Add quick-fix to convert child: to children: (Closed)
Patch Set: 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/correction/fix.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/correction/assist_internal.dart
diff --git a/pkg/analysis_server/lib/src/services/correction/assist_internal.dart b/pkg/analysis_server/lib/src/services/correction/assist_internal.dart
index 18d32b1d712c8e215e82a5748824be0c6614e36f..e75b7cb31b87af543a94a0ebe1fa95c95249695a 100644
--- a/pkg/analysis_server/lib/src/services/correction/assist_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/assist_internal.dart
@@ -11,6 +11,7 @@ import 'package:analysis_server/plugin/edit/assist/assist_core.dart';
import 'package:analysis_server/plugin/edit/assist/assist_dart.dart';
import 'package:analysis_server/src/protocol_server.dart' hide Element;
import 'package:analysis_server/src/services/correction/assist.dart';
+import 'package:analysis_server/src/services/correction/flutter_util.dart';
import 'package:analysis_server/src/services/correction/name_suggestion.dart';
import 'package:analysis_server/src/services/correction/source_buffer.dart';
import 'package:analysis_server/src/services/correction/source_range.dart';
@@ -36,10 +37,6 @@ typedef _SimpleIdentifierVisitor(SimpleIdentifier node);
* The computer for Dart assists.
*/
class AssistProcessor {
- static const FLUTTER_WIDGET_NAME = "Widget";
- static const FLUTTER_WIDGET_URI =
- "package:flutter/src/widgets/framework.dart";
-
AnalysisContext analysisContext;
Source source;
@@ -521,55 +518,39 @@ class AssistProcessor {
return;
}
InstanceCreationExpression newExpr = namedExp.parent.parent;
- if (newExpr == null || !_isFlutterInstanceCreationExpression(newExpr)) {
+ if (newExpr == null || !isFlutterInstanceCreationExpression(newExpr)) {
return;
}
} else {
- InstanceCreationExpression newExpr = _identifyNewExpression();
- if (newExpr == null || !_isFlutterInstanceCreationExpression(newExpr)) {
+ InstanceCreationExpression newExpr = identifyNewExpression(node);
+ if (newExpr == null || !isFlutterInstanceCreationExpression(newExpr)) {
_coverageMarker();
return;
}
- namedExp = _findChildArgument(newExpr);
+ namedExp = findChildArgument(newExpr);
if (namedExp == null || namedExp.expression == null) {
_coverageMarker();
return;
}
}
- InstanceCreationExpression childArg = _getChildWidget(namedExp, false);
+ InstanceCreationExpression childArg = getChildWidget(namedExp, false);
if (childArg == null) {
_coverageMarker();
return;
}
- int childLoc = namedExp.offset + 'child'.length;
- _addInsertEdit(childLoc, 'ren');
- int listLoc = childArg.offset;
- String childArgSrc = utils.getNodeText(childArg);
- if (!childArgSrc.contains(eol)) {
- _addInsertEdit(listLoc, '<Widget>[');
- _addInsertEdit(listLoc + childArg.length, ']');
- } else {
- int newlineLoc = childArgSrc.lastIndexOf(eol);
- if (newlineLoc == childArgSrc.length) {
- newlineLoc -= 1;
- }
- String indentOld = utils.getLinePrefix(childArg.offset + 1 + newlineLoc);
- String indentNew = '$indentOld${utils.getIndent(1)}';
- // The separator includes 'child:' but that has no newlines.
- String separator =
- utils.getText(namedExp.offset, childArg.offset - namedExp.offset);
- String prefix = separator.contains(eol) ? "" : "$eol$indentNew";
- if (prefix.isEmpty) {
- _addInsertEdit(namedExp.offset + 'child:'.length, ' <Widget>[');
- _addRemoveEdit(rangeStartLength(childArg.offset - 2, 2));
- } else {
- _addInsertEdit(listLoc, '<Widget>[');
- }
- String newChildArgSrc = childArgSrc.replaceAll(
- new RegExp("^$indentOld", multiLine: true), "$indentNew");
- newChildArgSrc = "$prefix$newChildArgSrc,$eol$indentOld]";
- _addReplaceEdit(rangeNode(childArg), newChildArgSrc);
- }
+ convertFlutterChildToChildren(
+ childArg,
+ namedExp,
+ eol,
+ utils.getNodeText,
+ utils.getLinePrefix,
+ utils.getIndent,
+ utils.getText,
+ _addInsertEdit,
+ _addRemoveEdit,
+ _addReplaceEdit,
+ rangeStartLength,
+ rangeNode);
_addAssist(DartAssistKind.CONVERT_FLUTTER_CHILD, []);
}
@@ -1635,18 +1616,18 @@ class AssistProcessor {
}
void _addProposal_moveFlutterWidgetDown() {
- InstanceCreationExpression exprGoingDown = _identifyNewExpression();
+ InstanceCreationExpression exprGoingDown = identifyNewExpression(node);
if (exprGoingDown == null ||
- !_isFlutterInstanceCreationExpression(exprGoingDown)) {
+ !isFlutterInstanceCreationExpression(exprGoingDown)) {
_coverageMarker();
return;
}
- InstanceCreationExpression exprGoingUp = _findChildWidget(exprGoingDown);
+ InstanceCreationExpression exprGoingUp = findChildWidget(exprGoingDown);
if (exprGoingUp == null) {
_coverageMarker();
return;
}
- NamedExpression stableChild = _findChildArgument(exprGoingUp);
+ NamedExpression stableChild = findChildArgument(exprGoingUp);
if (stableChild == null || stableChild.expression == null) {
_coverageMarker();
return;
@@ -1668,9 +1649,9 @@ class AssistProcessor {
}
void _addProposal_moveFlutterWidgetUp() {
- InstanceCreationExpression exprGoingUp = _identifyNewExpression();
+ InstanceCreationExpression exprGoingUp = identifyNewExpression(node);
if (exprGoingUp == null ||
- !_isFlutterInstanceCreationExpression(exprGoingUp)) {
+ !isFlutterInstanceCreationExpression(exprGoingUp)) {
_coverageMarker();
return;
}
@@ -1680,7 +1661,7 @@ class AssistProcessor {
return;
}
InstanceCreationExpression exprGoingDown = expr;
- NamedExpression stableChild = _findChildArgument(exprGoingUp);
+ NamedExpression stableChild = findChildArgument(exprGoingUp);
if (stableChild == null || stableChild.expression == null) {
_coverageMarker();
return;
@@ -1744,7 +1725,7 @@ class AssistProcessor {
}
if ((node as ListLiteral).elements.any((Expression exp) =>
!(exp is InstanceCreationExpression &&
- _isFlutterInstanceCreationExpression(exp)))) {
+ isFlutterInstanceCreationExpression(exp)))) {
_coverageMarker();
return;
}
@@ -1785,8 +1766,8 @@ class AssistProcessor {
}
void _addProposal_reparentFlutterWidget() {
- InstanceCreationExpression newExpr = _identifyNewExpression();
- if (newExpr == null || !_isFlutterInstanceCreationExpression(newExpr)) {
+ InstanceCreationExpression newExpr = identifyNewExpression(node);
+ if (newExpr == null || !isFlutterInstanceCreationExpression(newExpr)) {
_coverageMarker();
return;
}
@@ -2368,30 +2349,6 @@ class AssistProcessor {
}
}
- NamedExpression _findChildArgument(InstanceCreationExpression newExpr) =>
- newExpr.argumentList.arguments.firstWhere(
- (arg) => arg is NamedExpression && arg.name.label.name == 'child',
- orElse: () => null);
-
- InstanceCreationExpression _findChildWidget(
- InstanceCreationExpression newExpr) {
- NamedExpression child = _findChildArgument(newExpr);
- return _getChildWidget(child);
- }
-
- InstanceCreationExpression _getChildWidget(NamedExpression child,
- [bool strict = false]) {
- if (child?.expression is InstanceCreationExpression) {
- InstanceCreationExpression childNewExpr = child.expression;
- if (_isFlutterInstanceCreationExpression(childNewExpr)) {
- if (!strict || (_findChildArgument(childNewExpr) != null)) {
- return childNewExpr;
- }
- }
- }
- return null;
- }
-
/**
* Returns an existing or just added [LinkedEditGroup] with [groupId].
*/
@@ -2418,22 +2375,6 @@ class AssistProcessor {
return utils.getRangeText(range);
}
- InstanceCreationExpression _identifyNewExpression() {
- InstanceCreationExpression newExpr;
- if (node is SimpleIdentifier) {
- if (node.parent is ConstructorName &&
- node.parent.parent is InstanceCreationExpression) {
- newExpr = node.parent.parent;
- } else if (node.parent?.parent is ConstructorName &&
- node.parent.parent?.parent is InstanceCreationExpression) {
- newExpr = node.parent.parent.parent;
- }
- } else if (node is InstanceCreationExpression) {
- newExpr = node;
- }
- return newExpr;
- }
-
/**
* Inserts the given [SourceBuilder] at its offset.
*/
@@ -2462,24 +2403,6 @@ class AssistProcessor {
}
}
- bool _isFlutterInstanceCreationExpression(
- InstanceCreationExpression newExpr) {
- ClassElement classElement = newExpr.staticElement?.enclosingElement;
- InterfaceType superType = classElement?.allSupertypes?.firstWhere(
- (InterfaceType type) => FLUTTER_WIDGET_NAME == type.name,
- orElse: () => null);
- if (superType == null) {
- _coverageMarker();
- return false;
- }
- Uri uri = superType.element?.source?.uri;
- if (uri.toString() != FLUTTER_WIDGET_URI) {
- _coverageMarker();
- return false;
- }
- return true;
- }
-
Position _newPosition(int offset) {
return new Position(file, offset);
}
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/correction/fix.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698