mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 12:24:24 +00:00
Drop the 'Flutter' word from names, expect that clients will use the 'flutter' import prefix.
R=brianwilkerson@google.com Bug: Change-Id: I0275557bad66f03ed0d1b8388119b168d70bfad4 Reviewed-on: https://dart-review.googlesource.com/16600 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
c2f1af6378
commit
4c86f98d7a
6 changed files with 69 additions and 58 deletions
|
@ -3,7 +3,8 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analysis_server/src/collections.dart';
|
||||
import 'package:analysis_server/src/services/correction/flutter_util.dart';
|
||||
import 'package:analysis_server/src/services/correction/flutter_util.dart'
|
||||
as flutter;
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/ast/visitor.dart';
|
||||
import 'package:analyzer/dart/element/element.dart' as engine;
|
||||
|
@ -418,12 +419,12 @@ class _FunctionBodyOutlinesVisitor extends RecursiveAstVisitor {
|
|||
|
||||
@override
|
||||
visitInstanceCreationExpression(InstanceCreationExpression node) {
|
||||
if (isFlutterWidgetCreation(node)) {
|
||||
if (flutter.isWidgetCreation(node)) {
|
||||
List<Outline> children = <Outline>[];
|
||||
node.argumentList
|
||||
.accept(new _FunctionBodyOutlinesVisitor(outlineComputer, children));
|
||||
|
||||
String text = getFlutterWidgetPresentationText(node);
|
||||
String text = flutter.getWidgetPresentationText(node);
|
||||
Element element = new Element(ElementKind.CONSTRUCTOR_INVOCATION, text, 0,
|
||||
location: outlineComputer._getLocationOffsetLength(node.offset, 0));
|
||||
|
||||
|
|
|
@ -8,7 +8,8 @@ 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/services/correction/flutter_util.dart'
|
||||
as flutter;
|
||||
import 'package:analysis_server/src/utilities/documentation.dart';
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/ast/token.dart';
|
||||
|
@ -240,7 +241,7 @@ class ArgListContributor extends DartCompletionContributor {
|
|||
// Optionally add Flutter child widget details.
|
||||
Element element = parameter.enclosingElement;
|
||||
if (element is ConstructorElement) {
|
||||
if (isFlutterWidget(element.enclosingElement) &&
|
||||
if (flutter.isWidget(element.enclosingElement) &&
|
||||
parameter.name == 'children') {
|
||||
String value = getDefaultStringParameterValue(parameter);
|
||||
if (value != null) {
|
||||
|
@ -320,9 +321,9 @@ class ArgListContributor extends DartCompletionContributor {
|
|||
bool _isInFlutterCreation(DartCompletionRequest request) {
|
||||
AstNode containingNode = request?.target?.containingNode;
|
||||
InstanceCreationExpression newExpr = containingNode != null
|
||||
? identifyNewExpression(containingNode.parent)
|
||||
? flutter.identifyNewExpression(containingNode.parent)
|
||||
: null;
|
||||
return newExpr != null && isFlutterWidgetCreation(newExpr);
|
||||
return newExpr != null && flutter.isWidgetCreation(newExpr);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,7 +8,8 @@ import 'dart:collection';
|
|||
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/services/correction/assist.dart';
|
||||
import 'package:analysis_server/src/services/correction/flutter_util.dart';
|
||||
import 'package:analysis_server/src/services/correction/flutter_util.dart'
|
||||
as flutter;
|
||||
import 'package:analysis_server/src/services/correction/name_suggestion.dart';
|
||||
import 'package:analysis_server/src/services/correction/statement_analyzer.dart';
|
||||
import 'package:analysis_server/src/services/correction/util.dart';
|
||||
|
@ -509,22 +510,23 @@ class AssistProcessor {
|
|||
return;
|
||||
}
|
||||
InstanceCreationExpression newExpr = namedExp.parent.parent;
|
||||
if (newExpr == null || !isFlutterWidgetCreation(newExpr)) {
|
||||
if (newExpr == null || !flutter.isWidgetCreation(newExpr)) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
InstanceCreationExpression newExpr = identifyNewExpression(node);
|
||||
if (newExpr == null || !isFlutterWidgetCreation(newExpr)) {
|
||||
InstanceCreationExpression newExpr = flutter.identifyNewExpression(node);
|
||||
if (newExpr == null || !flutter.isWidgetCreation(newExpr)) {
|
||||
_coverageMarker();
|
||||
return;
|
||||
}
|
||||
namedExp = findChildArgument(newExpr);
|
||||
namedExp = flutter.findChildArgument(newExpr);
|
||||
if (namedExp == null || namedExp.expression == null) {
|
||||
_coverageMarker();
|
||||
return;
|
||||
}
|
||||
}
|
||||
InstanceCreationExpression childArg = getChildWidget(namedExp, false);
|
||||
InstanceCreationExpression childArg =
|
||||
flutter.getChildWidget(namedExp, false);
|
||||
if (childArg == null) {
|
||||
_coverageMarker();
|
||||
return;
|
||||
|
@ -1654,17 +1656,19 @@ class AssistProcessor {
|
|||
}
|
||||
|
||||
Future<Null> _addProposal_moveFlutterWidgetDown() async {
|
||||
InstanceCreationExpression exprGoingDown = identifyNewExpression(node);
|
||||
if (exprGoingDown == null || !isFlutterWidgetCreation(exprGoingDown)) {
|
||||
InstanceCreationExpression exprGoingDown =
|
||||
flutter.identifyNewExpression(node);
|
||||
if (exprGoingDown == null || !flutter.isWidgetCreation(exprGoingDown)) {
|
||||
_coverageMarker();
|
||||
return;
|
||||
}
|
||||
InstanceCreationExpression exprGoingUp = findChildWidget(exprGoingDown);
|
||||
InstanceCreationExpression exprGoingUp =
|
||||
flutter.findChildWidget(exprGoingDown);
|
||||
if (exprGoingUp == null) {
|
||||
_coverageMarker();
|
||||
return;
|
||||
}
|
||||
NamedExpression stableChild = findChildArgument(exprGoingUp);
|
||||
NamedExpression stableChild = flutter.findChildArgument(exprGoingUp);
|
||||
if (stableChild == null || stableChild.expression == null) {
|
||||
_coverageMarker();
|
||||
return;
|
||||
|
@ -1686,8 +1690,9 @@ class AssistProcessor {
|
|||
}
|
||||
|
||||
Future<Null> _addProposal_moveFlutterWidgetUp() async {
|
||||
InstanceCreationExpression exprGoingUp = identifyNewExpression(node);
|
||||
if (exprGoingUp == null || !isFlutterWidgetCreation(exprGoingUp)) {
|
||||
InstanceCreationExpression exprGoingUp =
|
||||
flutter.identifyNewExpression(node);
|
||||
if (exprGoingUp == null || !flutter.isWidgetCreation(exprGoingUp)) {
|
||||
_coverageMarker();
|
||||
return;
|
||||
}
|
||||
|
@ -1697,7 +1702,7 @@ class AssistProcessor {
|
|||
return;
|
||||
}
|
||||
InstanceCreationExpression exprGoingDown = expr;
|
||||
NamedExpression stableChild = findChildArgument(exprGoingUp);
|
||||
NamedExpression stableChild = flutter.findChildArgument(exprGoingUp);
|
||||
if (stableChild == null || stableChild.expression == null) {
|
||||
_coverageMarker();
|
||||
return;
|
||||
|
@ -1762,7 +1767,8 @@ class AssistProcessor {
|
|||
return;
|
||||
}
|
||||
if ((node as ListLiteral).elements.any((Expression exp) =>
|
||||
!(exp is InstanceCreationExpression && isFlutterWidgetCreation(exp)))) {
|
||||
!(exp is InstanceCreationExpression &&
|
||||
flutter.isWidgetCreation(exp)))) {
|
||||
_coverageMarker();
|
||||
return;
|
||||
}
|
||||
|
@ -1805,8 +1811,8 @@ class AssistProcessor {
|
|||
}
|
||||
|
||||
Future<Null> _addProposal_reparentFlutterWidget() async {
|
||||
InstanceCreationExpression newExpr = identifyNewExpression(node);
|
||||
if (newExpr == null || !isFlutterWidgetCreation(newExpr)) {
|
||||
InstanceCreationExpression newExpr = flutter.identifyNewExpression(node);
|
||||
if (newExpr == null || !flutter.isWidgetCreation(newExpr)) {
|
||||
_coverageMarker();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,8 @@ import 'package:analysis_server/plugin/edit/fix/fix_core.dart';
|
|||
import 'package:analysis_server/plugin/edit/fix/fix_dart.dart';
|
||||
import 'package:analysis_server/src/services/completion/dart/utilities.dart';
|
||||
import 'package:analysis_server/src/services/correction/fix.dart';
|
||||
import 'package:analysis_server/src/services/correction/flutter_util.dart';
|
||||
import 'package:analysis_server/src/services/correction/flutter_util.dart'
|
||||
as flutter;
|
||||
import 'package:analysis_server/src/services/correction/levenshtein.dart';
|
||||
import 'package:analysis_server/src/services/correction/namespace.dart';
|
||||
import 'package:analysis_server/src/services/correction/strings.dart';
|
||||
|
@ -642,8 +643,9 @@ class FixProcessor {
|
|||
String defaultValue = getDefaultStringParameterValue(element);
|
||||
builder.write('$paramName: $defaultValue');
|
||||
// Insert a trailing comma after Flutter instance creation params.
|
||||
InstanceCreationExpression newExpr = identifyNewExpression(node);
|
||||
if (newExpr != null && isFlutterWidgetCreation(newExpr)) {
|
||||
InstanceCreationExpression newExpr =
|
||||
flutter.identifyNewExpression(node);
|
||||
if (newExpr != null && flutter.isWidgetCreation(newExpr)) {
|
||||
builder.write(',');
|
||||
}
|
||||
});
|
||||
|
@ -749,15 +751,16 @@ class FixProcessor {
|
|||
}
|
||||
|
||||
Future<Null> _addFix_convertFlutterChild() async {
|
||||
NamedExpression namedExp = findFlutterNamedExpression(node, 'child');
|
||||
NamedExpression namedExp = flutter.findNamedExpression(node, 'child');
|
||||
if (namedExp == null) {
|
||||
return;
|
||||
}
|
||||
InstanceCreationExpression childArg = getChildWidget(namedExp, false);
|
||||
InstanceCreationExpression childArg =
|
||||
flutter.getChildWidget(namedExp, false);
|
||||
if (childArg != null) {
|
||||
DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
|
||||
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
|
||||
convertFlutterChildToChildren2(
|
||||
flutter.convertChildToChildren2(
|
||||
builder,
|
||||
childArg,
|
||||
namedExp,
|
||||
|
@ -771,7 +774,7 @@ class FixProcessor {
|
|||
_addFixFromBuilder(changeBuilder, DartFixKind.CONVERT_FLUTTER_CHILD);
|
||||
return;
|
||||
}
|
||||
ListLiteral listArg = getChildList(namedExp);
|
||||
ListLiteral listArg = flutter.getChildList(namedExp);
|
||||
if (listArg != null) {
|
||||
DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
|
||||
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
|
||||
|
|
|
@ -8,10 +8,10 @@ import 'package:analyzer/dart/element/type.dart';
|
|||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:analyzer_plugin/utilities/change_builder/change_builder_dart.dart';
|
||||
|
||||
const _FLUTTER_WIDGET_NAME = "Widget";
|
||||
const _FLUTTER_WIDGET_URI = "package:flutter/src/widgets/framework.dart";
|
||||
const _WIDGET_NAME = "Widget";
|
||||
const _WIDGET_URI = "package:flutter/src/widgets/framework.dart";
|
||||
|
||||
void convertFlutterChildToChildren(
|
||||
void convertChildToChildren(
|
||||
InstanceCreationExpression childArg,
|
||||
NamedExpression namedExp,
|
||||
String eol,
|
||||
|
@ -54,7 +54,7 @@ void convertFlutterChildToChildren(
|
|||
}
|
||||
}
|
||||
|
||||
void convertFlutterChildToChildren2(
|
||||
void convertChildToChildren2(
|
||||
DartFileEditBuilder builder,
|
||||
InstanceCreationExpression childArg,
|
||||
NamedExpression namedExp,
|
||||
|
@ -119,7 +119,7 @@ InstanceCreationExpression findChildWidget(InstanceCreationExpression newExpr) {
|
|||
* name is the given [name] that is an argument to a Flutter instance creation
|
||||
* expression. Return null if any condition cannot be satisfied.
|
||||
*/
|
||||
NamedExpression findFlutterNamedExpression(AstNode node, String name) {
|
||||
NamedExpression findNamedExpression(AstNode node, String name) {
|
||||
if (node is! SimpleIdentifier) {
|
||||
return null;
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ NamedExpression findFlutterNamedExpression(AstNode node, String name) {
|
|||
return null;
|
||||
}
|
||||
InstanceCreationExpression newExpr = namedExp.parent.parent;
|
||||
if (newExpr == null || !isFlutterWidgetCreation(newExpr)) {
|
||||
if (newExpr == null || !isWidgetCreation(newExpr)) {
|
||||
return null;
|
||||
}
|
||||
return namedExp;
|
||||
|
@ -149,7 +149,7 @@ ListLiteral getChildList(NamedExpression child) {
|
|||
if (list.elements.isEmpty ||
|
||||
list.elements.every((element) =>
|
||||
element is InstanceCreationExpression &&
|
||||
isFlutterWidgetCreation(element))) {
|
||||
isWidgetCreation(element))) {
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ InstanceCreationExpression getChildWidget(NamedExpression child,
|
|||
[bool strict = false]) {
|
||||
if (child?.expression is InstanceCreationExpression) {
|
||||
InstanceCreationExpression childNewExpr = child.expression;
|
||||
if (isFlutterWidgetCreation(childNewExpr)) {
|
||||
if (isWidgetCreation(childNewExpr)) {
|
||||
if (!strict || (findChildArgument(childNewExpr) != null)) {
|
||||
return childNewExpr;
|
||||
}
|
||||
|
@ -177,9 +177,9 @@ InstanceCreationExpression getChildWidget(NamedExpression child,
|
|||
/**
|
||||
* Return the presentation for the given Flutter `Widget` creation [node].
|
||||
*/
|
||||
String getFlutterWidgetPresentationText(InstanceCreationExpression node) {
|
||||
String getWidgetPresentationText(InstanceCreationExpression node) {
|
||||
ClassElement element = node.staticElement?.enclosingElement;
|
||||
if (!isFlutterWidget(element)) {
|
||||
if (!isWidget(element)) {
|
||||
return null;
|
||||
}
|
||||
// TODO(scheglov) check that the required argument is actually provided.
|
||||
|
@ -224,14 +224,14 @@ InstanceCreationExpression identifyNewExpression(AstNode node) {
|
|||
* Return `true` if the given [element] has the Flutter class `Widget` as
|
||||
* a superclass.
|
||||
*/
|
||||
bool isFlutterWidget(ClassElement element) {
|
||||
bool isWidget(ClassElement element) {
|
||||
if (element == null) {
|
||||
return false;
|
||||
}
|
||||
for (InterfaceType type in element.allSupertypes) {
|
||||
if (type.name == _FLUTTER_WIDGET_NAME) {
|
||||
if (type.name == _WIDGET_NAME) {
|
||||
Uri uri = type.element.source.uri;
|
||||
if (uri.toString() == _FLUTTER_WIDGET_URI) {
|
||||
if (uri.toString() == _WIDGET_URI) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -243,9 +243,9 @@ bool isFlutterWidget(ClassElement element) {
|
|||
* Return `true` if the given [expr] is a constructor invocation for a
|
||||
* class that has the Flutter class `Widget` as a superclass.
|
||||
*/
|
||||
bool isFlutterWidgetCreation(InstanceCreationExpression expr) {
|
||||
bool isWidgetCreation(InstanceCreationExpression expr) {
|
||||
ClassElement element = expr.staticElement?.enclosingElement;
|
||||
return isFlutterWidget(element);
|
||||
return isWidget(element);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,7 +32,7 @@ import 'package:flutter/material.dart';
|
|||
var w = const Icon(Icons.book);
|
||||
''');
|
||||
var w = _getTopVariableCreation('w');
|
||||
expect(getFlutterWidgetPresentationText(w), "Icon(Icons.book)");
|
||||
expect(getWidgetPresentationText(w), "Icon(Icons.book)");
|
||||
}
|
||||
|
||||
test_getFlutterWidgetPresentationText_notWidget() async {
|
||||
|
@ -41,7 +41,7 @@ import 'package:flutter/material.dart';
|
|||
var w = new Object();
|
||||
''');
|
||||
var w = _getTopVariableCreation('w');
|
||||
expect(getFlutterWidgetPresentationText(w), isNull);
|
||||
expect(getWidgetPresentationText(w), isNull);
|
||||
}
|
||||
|
||||
test_getFlutterWidgetPresentationText_text() async {
|
||||
|
@ -50,7 +50,7 @@ import 'package:flutter/material.dart';
|
|||
var w = const Text('foo');
|
||||
''');
|
||||
var w = _getTopVariableCreation('w');
|
||||
expect(getFlutterWidgetPresentationText(w), "Text('foo')");
|
||||
expect(getWidgetPresentationText(w), "Text('foo')");
|
||||
}
|
||||
|
||||
test_getFlutterWidgetPresentationText_text_longText() async {
|
||||
|
@ -59,8 +59,8 @@ import 'package:flutter/material.dart';
|
|||
var w = const Text('${'abc' * 100}');
|
||||
''');
|
||||
var w = _getTopVariableCreation('w');
|
||||
expect(getFlutterWidgetPresentationText(w),
|
||||
"Text('abcabcabcabca...cabcabcabcabc')");
|
||||
expect(
|
||||
getWidgetPresentationText(w), "Text('abcabcabcabca...cabcabcabcabc')");
|
||||
}
|
||||
|
||||
test_getFlutterWidgetPresentationText_unresolved() async {
|
||||
|
@ -70,7 +70,7 @@ import 'package:flutter/material.dart';
|
|||
var w = new Foo();
|
||||
''');
|
||||
var w = _getTopVariableCreation('w');
|
||||
expect(getFlutterWidgetPresentationText(w), isNull);
|
||||
expect(getWidgetPresentationText(w), isNull);
|
||||
}
|
||||
|
||||
test_isFlutterWidget() async {
|
||||
|
@ -84,19 +84,19 @@ class NotFlutter {}
|
|||
class NotWidget extends State {}
|
||||
''');
|
||||
var myStatelessWidget = testUnitElement.getType('MyStatelessWidget');
|
||||
expect(isFlutterWidget(myStatelessWidget), isTrue);
|
||||
expect(isWidget(myStatelessWidget), isTrue);
|
||||
|
||||
var myStatefulWidget = testUnitElement.getType('MyStatefulWidget');
|
||||
expect(isFlutterWidget(myStatefulWidget), isTrue);
|
||||
expect(isWidget(myStatefulWidget), isTrue);
|
||||
|
||||
var myContainer = testUnitElement.getType('MyContainer');
|
||||
expect(isFlutterWidget(myContainer), isTrue);
|
||||
expect(isWidget(myContainer), isTrue);
|
||||
|
||||
var notFlutter = testUnitElement.getType('NotFlutter');
|
||||
expect(isFlutterWidget(notFlutter), isFalse);
|
||||
expect(isWidget(notFlutter), isFalse);
|
||||
|
||||
var notWidget = testUnitElement.getType('NotWidget');
|
||||
expect(isFlutterWidget(notWidget), isFalse);
|
||||
expect(isWidget(notWidget), isFalse);
|
||||
}
|
||||
|
||||
test_isFlutterWidgetCreation() async {
|
||||
|
@ -107,10 +107,10 @@ var a = new Object();
|
|||
var b = new Text('bbb');
|
||||
''');
|
||||
InstanceCreationExpression a = _getTopVariableCreation('a');
|
||||
expect(isFlutterWidgetCreation(a), isFalse);
|
||||
expect(isWidgetCreation(a), isFalse);
|
||||
|
||||
InstanceCreationExpression b = _getTopVariableCreation('b');
|
||||
expect(isFlutterWidgetCreation(b), isTrue);
|
||||
expect(isWidgetCreation(b), isTrue);
|
||||
}
|
||||
|
||||
VariableDeclaration _getTopVariable(String name, [CompilationUnit unit]) {
|
||||
|
|
Loading…
Reference in a new issue