[DAS] Differentiates tearoff fixes from invocation fixes for methods and functions
This is mostly a no-op change to make clear to anyone reading the tests that we should probably make sure both cases are covered. This is a step towards https://github.com/dart-lang/sdk/issues/61186#issuecomment-3113493861 which will be handled in a separate CL.
Bug: https://github.com/dart-lang/sdk/issues/61186
Change-Id: Ib651e2d1126a7fd54ba37fe3a806d843c0f29ca4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/444384
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/create_method_or_function.dart b/pkg/analysis_server/lib/src/services/correction/dart/create_method_or_function.dart
index 3ede725..e8d60c4 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/create_method_or_function.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/create_method_or_function.dart
@@ -27,7 +27,10 @@
factory CreateMethodOrFunction({required CorrectionProducerContext context}) {
if (context is StubCorrectionProducerContext) {
- return CreateMethodOrFunction._(context: context);
+ return CreateMethodOrFunction._(
+ context: context,
+ fixKind: DartFixKind.CREATE_FUNCTION_TEAROFF,
+ );
}
if (context.node case SimpleIdentifier node) {
@@ -54,18 +57,21 @@
targetElement: targetElement,
fixKind:
targetElement is InterfaceElement
- ? DartFixKind.CREATE_METHOD
- : DartFixKind.CREATE_FUNCTION,
+ ? DartFixKind.CREATE_METHOD_TEAROFF
+ : DartFixKind.CREATE_FUNCTION_TEAROFF,
);
}
- return CreateMethodOrFunction._(context: context);
+ return CreateMethodOrFunction._(
+ context: context,
+ fixKind: DartFixKind.CREATE_FUNCTION_TEAROFF,
+ );
}
CreateMethodOrFunction._({
required super.context,
Element? targetElement,
- this.fixKind = DartFixKind.CREATE_METHOD,
+ required this.fixKind,
}) : _targetElement = targetElement;
@override
diff --git a/pkg/analysis_server/lib/src/services/correction/fix.dart b/pkg/analysis_server/lib/src/services/correction/fix.dart
index 1dd934d..202b2ba 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix.dart
@@ -808,6 +808,11 @@
DartFixKindPriority.standard - 1,
"Create function '{0}'",
);
+ static const CREATE_FUNCTION_TEAROFF = FixKind(
+ 'dart.fix.create.function.tearoff',
+ DartFixKindPriority.standard - 1,
+ "Create function '{0}'",
+ );
static const CREATE_GETTER = FixKind(
'dart.fix.create.getter',
DartFixKindPriority.standard,
@@ -823,6 +828,11 @@
DartFixKindPriority.standard,
"Create method '{0}'",
);
+ static const CREATE_METHOD_TEAROFF = FixKind(
+ 'dart.fix.create.method.tearoff',
+ DartFixKindPriority.standard,
+ "Create method '{0}'",
+ );
// TODO(pq): used by LintNames.hash_and_equals; consider removing.
static const CREATE_METHOD_MULTI = FixKind(
diff --git a/pkg/analysis_server/test/src/services/correction/fix/create_function_test.dart b/pkg/analysis_server/test/src/services/correction/fix/create_function_test.dart
index 080cb09..cd5ed26 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/create_function_test.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/create_function_test.dart
@@ -11,11 +11,299 @@
void main() {
defineReflectiveSuite(() {
+ defineReflectiveTests(CreateFunctionTearoffTest);
defineReflectiveTests(CreateFunctionTest);
});
}
@reflectiveTest
+class CreateFunctionTearoffTest extends FixProcessorTest {
+ @override
+ FixKind get kind => DartFixKind.CREATE_FUNCTION_TEAROFF;
+
+ Future<void> test_assignment() async {
+ await resolveTestCode('''
+bool Function() f = g;
+''');
+ await assertHasFix('''
+bool Function() f = g;
+
+bool g() {
+}
+''');
+ }
+
+ Future<void> test_functionType_cascadeSecond() async {
+ await resolveTestCode('''
+class A {
+ B ma() => throw 0;
+}
+class B {
+ useFunction(int g(double a, String b)) {}
+}
+
+void f() {
+ A a = new A();
+ a..ma().useFunction(test);
+}
+''');
+ await assertHasFix('''
+class A {
+ B ma() => throw 0;
+}
+class B {
+ useFunction(int g(double a, String b)) {}
+}
+
+void f() {
+ A a = new A();
+ a..ma().useFunction(test);
+}
+
+int test(double a, String b) {
+}
+''');
+ }
+
+ Future<void> test_functionType_coreFunction() async {
+ await resolveTestCode('''
+void f() {
+ useFunction(g: test);
+}
+useFunction({Function? g}) {}
+''');
+ await assertHasFix('''
+void f() {
+ useFunction(g: test);
+}
+useFunction({Function? g}) {}
+
+test() {
+}
+''');
+ }
+
+ Future<void> test_functionType_dynamicArgument() async {
+ await resolveTestCode('''
+void f() {
+ useFunction(test);
+}
+useFunction(int g(a, b)) {}
+''');
+ await assertHasFix('''
+void f() {
+ useFunction(test);
+}
+useFunction(int g(a, b)) {}
+
+int test(a, b) {
+}
+''');
+ }
+
+ Future<void> test_functionType_function() async {
+ await resolveTestCode('''
+void f() {
+ useFunction(test);
+}
+useFunction(int g(double a, String b)) {}
+''');
+ await assertHasFix('''
+void f() {
+ useFunction(test);
+}
+useFunction(int g(double a, String b)) {}
+
+int test(double a, String b) {
+}
+''');
+ }
+
+ Future<void> test_functionType_function_namedArgument() async {
+ await resolveTestCode('''
+void f() {
+ useFunction(g: test);
+}
+useFunction({int g(double a, String b)?}) {}
+''');
+ await assertHasFix('''
+void f() {
+ useFunction(g: test);
+}
+useFunction({int g(double a, String b)?}) {}
+
+int test(double a, String b) {
+}
+''');
+ }
+
+ Future<void> test_functionType_FunctionCall() async {
+ await resolveTestCode('''
+void f1(int i) {
+ f2(f3);
+}
+
+void f2(int Function() f) {}
+''');
+ await assertHasFix('''
+void f1(int i) {
+ f2(f3);
+}
+
+void f2(int Function() f) {}
+
+int f3() {
+}
+''');
+ }
+
+ Future<void> test_functionType_importType() async {
+ newFile('$testPackageLibPath/a.dart', r'''
+class A {}
+''');
+ newFile('$testPackageLibPath/b.dart', r'''
+import 'package:test/a.dart';
+
+useFunction(int g(A a)) {}
+''');
+ await resolveTestCode('''
+import 'package:test/b.dart';
+
+void f() {
+ useFunction(test);
+}
+''');
+ await assertHasFix('''
+import 'package:test/a.dart';
+import 'package:test/b.dart';
+
+void f() {
+ useFunction(test);
+}
+
+int test(A a) {
+}
+''');
+ }
+
+ Future<void> test_functionType_inside_conditional_operator() async {
+ await resolveTestCode('''
+void f1(int i) {
+ f2(i == 0 ? f3 : (v) => v);
+}
+
+void f2(int Function(int) f) {}
+''');
+ await assertHasFix('''
+void f1(int i) {
+ f2(i == 0 ? f3 : (v) => v);
+}
+
+void f2(int Function(int) f) {}
+
+int f3(int p1) {
+}
+''');
+ }
+
+ Future<void> test_functionType_inside_conditional_operator_else() async {
+ await resolveTestCode('''
+void f1(int i) {
+ f2(i == 0 ? (v) => v : f3);
+}
+
+void f2(int Function(int) f) {}
+''');
+ await assertHasFix('''
+void f1(int i) {
+ f2(i == 0 ? (v) => v : f3);
+}
+
+void f2(int Function(int) f) {}
+
+int f3(int p1) {
+}
+''');
+ }
+
+ Future<void> test_functionType_inside_record_functionType() async {
+ await resolveTestCode('''
+void f1(int i) {
+ f2((0, f3));
+}
+
+void f2((int, int Function(int)) f) {}
+''');
+ await assertHasFix('''
+void f1(int i) {
+ f2((0, f3));
+}
+
+void f2((int, int Function(int)) f) {}
+
+int f3(int p1) {
+}
+''');
+ }
+
+ Future<void> test_functionType_inside_record_functionType_named() async {
+ await resolveTestCode('''
+void f1(int i) {
+ f2((f: f3));
+}
+
+void f2(({int Function(int) f}) f) {}
+''');
+ await assertHasFix('''
+void f1(int i) {
+ f2((f: f3));
+}
+
+void f2(({int Function(int) f}) f) {}
+
+int f3(int p1) {
+}
+''');
+ }
+
+ Future<void> test_record_tearoff() async {
+ await resolveTestCode('''
+(bool Function(),) f = (g,);
+''');
+ await assertHasFix('''
+(bool Function(),) f = (g,);
+
+bool g() {
+}
+''');
+ }
+
+ Future<void> test_returnType_typeAlias_function() async {
+ await resolveTestCode('''
+typedef A<T> = void Function(T a);
+
+void f(A<int> Function() a) {}
+
+void g() {
+ f(test);
+}
+''');
+ await assertHasFix('''
+typedef A<T> = void Function(T a);
+
+void f(A<int> Function() a) {}
+
+void g() {
+ f(test);
+}
+
+A<int> test() {
+}
+''');
+ }
+}
+
+@reflectiveTest
class CreateFunctionTest extends FixProcessorTest {
@override
FixKind get kind => DartFixKind.CREATE_FUNCTION;
@@ -50,18 +338,6 @@
''');
}
- Future<void> test_assignment_tearoff() async {
- await resolveTestCode('''
-bool Function() f = g;
-''');
- await assertHasFix('''
-bool Function() f = g;
-
-bool g() {
-}
-''');
- }
-
Future<void> test_await_infer_from_parent() async {
await resolveTestCode('''
Future<void> f() async {
@@ -280,179 +556,6 @@
''');
}
- Future<void> test_functionType_cascadeSecond() async {
- await resolveTestCode('''
-class A {
- B ma() => throw 0;
-}
-class B {
- useFunction(int g(double a, String b)) {}
-}
-
-void f() {
- A a = new A();
- a..ma().useFunction(test);
-}
-''');
- await assertHasFix('''
-class A {
- B ma() => throw 0;
-}
-class B {
- useFunction(int g(double a, String b)) {}
-}
-
-void f() {
- A a = new A();
- a..ma().useFunction(test);
-}
-
-int test(double a, String b) {
-}
-''');
- }
-
- Future<void> test_functionType_coreFunction() async {
- await resolveTestCode('''
-void f() {
- useFunction(g: test);
-}
-useFunction({Function? g}) {}
-''');
- await assertHasFix('''
-void f() {
- useFunction(g: test);
-}
-useFunction({Function? g}) {}
-
-test() {
-}
-''');
- }
-
- Future<void> test_functionType_dynamicArgument() async {
- await resolveTestCode('''
-void f() {
- useFunction(test);
-}
-useFunction(int g(a, b)) {}
-''');
- await assertHasFix('''
-void f() {
- useFunction(test);
-}
-useFunction(int g(a, b)) {}
-
-int test(a, b) {
-}
-''');
- }
-
- Future<void> test_functionType_function() async {
- await resolveTestCode('''
-void f() {
- useFunction(test);
-}
-useFunction(int g(double a, String b)) {}
-''');
- await assertHasFix('''
-void f() {
- useFunction(test);
-}
-useFunction(int g(double a, String b)) {}
-
-int test(double a, String b) {
-}
-''');
- }
-
- Future<void> test_functionType_function_namedArgument() async {
- await resolveTestCode('''
-void f() {
- useFunction(g: test);
-}
-useFunction({int g(double a, String b)?}) {}
-''');
- await assertHasFix('''
-void f() {
- useFunction(g: test);
-}
-useFunction({int g(double a, String b)?}) {}
-
-int test(double a, String b) {
-}
-''');
- }
-
- Future<void> test_functionType_FunctionCall() async {
- await resolveTestCode('''
-void f1(int i) {
- f2(f3);
-}
-
-void f2(int Function() f) {}
-''');
- await assertHasFix('''
-void f1(int i) {
- f2(f3);
-}
-
-void f2(int Function() f) {}
-
-int f3() {
-}
-''');
- }
-
- Future<void> test_functionType_importType() async {
- newFile('$testPackageLibPath/a.dart', r'''
-class A {}
-''');
- newFile('$testPackageLibPath/b.dart', r'''
-import 'package:test/a.dart';
-
-useFunction(int g(A a)) {}
-''');
- await resolveTestCode('''
-import 'package:test/b.dart';
-
-void f() {
- useFunction(test);
-}
-''');
- await assertHasFix('''
-import 'package:test/a.dart';
-import 'package:test/b.dart';
-
-void f() {
- useFunction(test);
-}
-
-int test(A a) {
-}
-''');
- }
-
- Future<void> test_functionType_inside_conditional_operator() async {
- await resolveTestCode('''
-void f1(int i) {
- f2(i == 0 ? f3 : (v) => v);
-}
-
-void f2(int Function(int) f) {}
-''');
- await assertHasFix('''
-void f1(int i) {
- f2(i == 0 ? f3 : (v) => v);
-}
-
-void f2(int Function(int) f) {}
-
-int f3(int p1) {
-}
-''');
- }
-
Future<void> test_functionType_inside_conditional_operator_condition() async {
await resolveTestCode('''
void f1(int i) {
@@ -485,26 +588,6 @@
''');
}
- Future<void> test_functionType_inside_conditional_operator_else() async {
- await resolveTestCode('''
-void f1(int i) {
- f2(i == 0 ? (v) => v : f3);
-}
-
-void f2(int Function(int) f) {}
-''');
- await assertHasFix('''
-void f1(int i) {
- f2(i == 0 ? (v) => v : f3);
-}
-
-void f2(int Function(int) f) {}
-
-int f3(int p1) {
-}
-''');
- }
-
Future<void>
test_functionType_inside_conditional_operator_else_FunctionCall() async {
await resolveTestCode('''
@@ -547,46 +630,6 @@
''');
}
- Future<void> test_functionType_inside_record_functionType() async {
- await resolveTestCode('''
-void f1(int i) {
- f2((0, f3));
-}
-
-void f2((int, int Function(int)) f) {}
-''');
- await assertHasFix('''
-void f1(int i) {
- f2((0, f3));
-}
-
-void f2((int, int Function(int)) f) {}
-
-int f3(int p1) {
-}
-''');
- }
-
- Future<void> test_functionType_inside_record_functionType_named() async {
- await resolveTestCode('''
-void f1(int i) {
- f2((f: f3));
-}
-
-void f2(({int Function(int) f}) f) {}
-''');
- await assertHasFix('''
-void f1(int i) {
- f2((f: f3));
-}
-
-void f2(({int Function(int) f}) f) {}
-
-int f3(int p1) {
-}
-''');
- }
-
Future<void> test_functionType_notFunctionType() async {
await resolveTestCode('''
void f(A a) {
@@ -726,18 +769,6 @@
''');
}
- Future<void> test_record_tearoff() async {
- await resolveTestCode('''
-(bool Function(),) f = (g,);
-''');
- await assertHasFix('''
-(bool Function(),) f = (g,);
-
-bool g() {
-}
-''');
- }
-
Future<void> test_returnType_bool_and_left() async {
await assert_returnType_bool('test() && b;');
}
@@ -918,30 +949,6 @@
''');
}
- Future<void> test_returnType_typeAlias_function() async {
- await resolveTestCode('''
-typedef A<T> = void Function(T a);
-
-void f(A<int> Function() a) {}
-
-void g() {
- f(test);
-}
-''');
- await assertHasFix('''
-typedef A<T> = void Function(T a);
-
-void f(A<int> Function() a) {}
-
-void g() {
- f(test);
-}
-
-A<int> test() {
-}
-''');
- }
-
Future<void> test_returnType_void() async {
await resolveTestCode('''
void f() {
diff --git a/pkg/analysis_server/test/src/services/correction/fix/create_method_test.dart b/pkg/analysis_server/test/src/services/correction/fix/create_method_test.dart
index b18f46a..77a7fd7 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/create_method_test.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/create_method_test.dart
@@ -14,6 +14,8 @@
defineReflectiveSuite(() {
defineReflectiveTests(AddMissingHashOrEqualsTest);
defineReflectiveTests(CreateMethodMixinTest);
+ defineReflectiveTests(CreateMethodTearoffMixinTest);
+ defineReflectiveTests(CreateMethodTearoffTest);
defineReflectiveTests(CreateMethodTest);
});
}
@@ -152,55 +154,6 @@
''');
}
- Future<void> test_functionType_method_enclosingMixin_static() async {
- await resolveTestCode('''
-mixin M {
- static foo() {
- useFunction(test);
- }
-}
-
-useFunction(int g(double a, String b)) {}
-''');
- await assertHasFix('''
-mixin M {
- static foo() {
- useFunction(test);
- }
-
- static int test(double a, String b) {
- }
-}
-
-useFunction(int g(double a, String b)) {}
-''');
- }
-
- Future<void> test_functionType_method_targetMixin() async {
- await resolveTestCode('''
-void f(M m) {
- useFunction(m.test);
-}
-
-mixin M {
-}
-
-useFunction(int g(double a, String b)) {}
-''');
- await assertHasFix('''
-void f(M m) {
- useFunction(m.test);
-}
-
-mixin M {
- int test(double a, String b) {
- }
-}
-
-useFunction(int g(double a, String b)) {}
-''');
- }
-
Future<void> test_main_part() async {
var partPath = join(testPackageLibPath, 'part.dart');
newFile(partPath, '''
@@ -279,6 +232,581 @@
}
@reflectiveTest
+class CreateMethodTearoffMixinTest extends FixProcessorTest {
+ @override
+ FixKind get kind => DartFixKind.CREATE_METHOD_TEAROFF;
+ Future<void> test_functionType_method_enclosingMixin_static() async {
+ await resolveTestCode('''
+mixin M {
+ static foo() {
+ useFunction(test);
+ }
+}
+
+useFunction(int g(double a, String b)) {}
+''');
+ await assertHasFix('''
+mixin M {
+ static foo() {
+ useFunction(test);
+ }
+
+ static int test(double a, String b) {
+ }
+}
+
+useFunction(int g(double a, String b)) {}
+''');
+ }
+
+ Future<void> test_functionType_method_targetMixin() async {
+ await resolveTestCode('''
+void f(M m) {
+ useFunction(m.test);
+}
+
+mixin M {
+}
+
+useFunction(int g(double a, String b)) {}
+''');
+ await assertHasFix('''
+void f(M m) {
+ useFunction(m.test);
+}
+
+mixin M {
+ int test(double a, String b) {
+ }
+}
+
+useFunction(int g(double a, String b)) {}
+''');
+ }
+}
+
+@reflectiveTest
+class CreateMethodTearoffTest extends FixProcessorTest {
+ @override
+ FixKind get kind => DartFixKind.CREATE_METHOD_TEAROFF;
+
+ Future<void> test_enum_tearoff() async {
+ await resolveTestCode('''
+enum E {
+ e1,
+ e2;
+}
+
+void g(int Function() f) {}
+
+void test(E e) {
+ g(e.bar);
+}
+''');
+ await assertHasFix('''
+enum E {
+ e1,
+ e2;
+ int bar() {
+ }
+}
+
+void g(int Function() f) {}
+
+void test(E e) {
+ g(e.bar);
+}
+''');
+ }
+
+ Future<void> test_enum_tearoff_static() async {
+ await resolveTestCode('''
+enum E {
+ e1,
+ e2;
+}
+
+void g(int Function() f) {}
+
+void test() {
+ g(E.bar);
+}
+''');
+ await assertHasFix('''
+enum E {
+ e1,
+ e2;
+ static int bar() {
+ }
+}
+
+void g(int Function() f) {}
+
+void test() {
+ g(E.bar);
+}
+''');
+ }
+
+ Future<void> test_extensionType_tearoff() async {
+ await resolveTestCode('''
+extension type E(int i) {
+}
+
+void g(int Function() f) {}
+
+void test(E e) {
+ g(e.bar);
+}
+''');
+ await assertHasFix('''
+extension type E(int i) {
+ int bar() {
+ }
+}
+
+void g(int Function() f) {}
+
+void test(E e) {
+ g(e.bar);
+}
+''');
+ }
+
+ Future<void> test_extensionType_tearoff_static() async {
+ await resolveTestCode('''
+extension type E(int i) {
+}
+
+void g(int Function() f) {}
+
+void test() {
+ g(E.bar);
+}
+''');
+ await assertHasFix('''
+extension type E(int i) {
+ static int bar() {
+ }
+}
+
+void g(int Function() f) {}
+
+void test() {
+ g(E.bar);
+}
+''');
+ }
+
+ Future<void> test_functionType_method_enclosingClass_instance() async {
+ await resolveTestCode('''
+class C {
+ void m1() {
+ m2(m3);
+ }
+
+ void m2(int Function(int) f) {}
+}
+''');
+ await assertHasFix('''
+class C {
+ void m1() {
+ m2(m3);
+ }
+
+ void m2(int Function(int) f) {}
+
+ int m3(int p1) {
+ }
+}
+''');
+ }
+
+ Future<void> test_functionType_method_enclosingClass_static() async {
+ await resolveTestCode('''
+class A {
+ static foo() {
+ useFunction(test);
+ }
+}
+useFunction(int g(double a, String b)) {}
+''');
+ await assertHasFix('''
+class A {
+ static foo() {
+ useFunction(test);
+ }
+
+ static int test(double a, String b) {
+ }
+}
+useFunction(int g(double a, String b)) {}
+''');
+ }
+
+ Future<void> test_functionType_method_enclosingClass_static2() async {
+ await resolveTestCode('''
+class A {
+ var f;
+ A() : f = useFunction(test);
+}
+useFunction(int g(double a, String b)) {}
+''');
+ await assertHasFix('''
+class A {
+ var f;
+ A() : f = useFunction(test);
+
+ static int test(double a, String b) {
+ }
+}
+useFunction(int g(double a, String b)) {}
+''');
+ }
+
+ Future<void> test_functionType_method_FunctionCall() async {
+ await resolveTestCode('''
+class C {
+ void m1(int i) {
+ m2(m3);
+ }
+
+ void m2(int Function() f) {}
+}
+''');
+ await assertHasFix('''
+class C {
+ void m1(int i) {
+ m2(m3);
+ }
+
+ void m2(int Function() f) {}
+
+ int m3() {
+ }
+}
+''');
+ }
+
+ Future<void>
+ test_functionType_method_inside_conditional_operator_else() async {
+ await resolveTestCode('''
+class C {
+ void m1(int i) {
+ m2(i == 0 ? (v) => v : m3);
+ }
+
+ void m2(int Function(int) f) {}
+}
+''');
+ await assertHasFix('''
+class C {
+ void m1(int i) {
+ m2(i == 0 ? (v) => v : m3);
+ }
+
+ void m2(int Function(int) f) {}
+
+ int m3(int p1) {
+ }
+}
+''');
+ }
+
+ Future<void>
+ test_functionType_method_inside_conditional_operator_then() async {
+ await resolveTestCode('''
+class C {
+ void m1(int i) {
+ m2(i == 0 ? m3 : (v) => v);
+ }
+
+ void m2(int Function(int) f) {}
+}
+''');
+ await assertHasFix('''
+class C {
+ void m1(int i) {
+ m2(i == 0 ? m3 : (v) => v);
+ }
+
+ void m2(int Function(int) f) {}
+
+ int m3(int p1) {
+ }
+}
+''');
+ }
+
+ Future<void> test_functionType_method_inside_record_functionType() async {
+ await resolveTestCode('''
+class C {
+ void m1(int i) {
+ m2((m3,));
+ }
+
+ void m2((int Function(int),) f) {}
+}
+''');
+ await assertHasFix('''
+class C {
+ void m1(int i) {
+ m2((m3,));
+ }
+
+ void m2((int Function(int),) f) {}
+
+ int m3(int p1) {
+ }
+}
+''');
+ }
+
+ Future<void>
+ test_functionType_method_inside_record_functionType_named() async {
+ await resolveTestCode('''
+class C {
+ void m1(int i) {
+ m2((f: m3));
+ }
+
+ void m2(({int Function(int) f}) f) {}
+}
+''');
+ await assertHasFix('''
+class C {
+ void m1(int i) {
+ m2((f: m3));
+ }
+
+ void m2(({int Function(int) f}) f) {}
+
+ int m3(int p1) {
+ }
+}
+''');
+ }
+
+ Future<void> test_functionType_method_targetClass() async {
+ await resolveTestCode('''
+void f(A a) {
+ useFunction(a.test);
+}
+class A {
+}
+useFunction(int g(double a, String b)) {}
+''');
+ await assertHasFix('''
+void f(A a) {
+ useFunction(a.test);
+}
+class A {
+ int test(double a, String b) {
+ }
+}
+useFunction(int g(double a, String b)) {}
+''');
+ }
+
+ Future<void> test_functionType_method_targetClass_hasOtherMember() async {
+ await resolveTestCode('''
+void f(A a) {
+ useFunction(a.test);
+}
+class A {
+ m() {}
+}
+useFunction(int g(double a, String b)) {}
+''');
+ await assertHasFix('''
+void f(A a) {
+ useFunction(a.test);
+}
+class A {
+ m() {}
+
+ int test(double a, String b) {
+ }
+}
+useFunction(int g(double a, String b)) {}
+''');
+ }
+
+ Future<void> test_record_named_tearoff() async {
+ await resolveTestCode('''
+class A {
+ ({bool Function() fn,}) m() => (fn: m2,);
+}
+''');
+ await assertHasFix('''
+class A {
+ ({bool Function() fn,}) m() => (fn: m2,);
+
+ bool m2() {
+ }
+}
+''');
+ }
+
+ Future<void> test_record_tearoff() async {
+ await resolveTestCode('''
+class A {
+ (bool Function(),) m() => (m2,);
+}
+''');
+ await assertHasFix('''
+class A {
+ (bool Function(),) m() => (m2,);
+
+ bool m2() {
+ }
+}
+''');
+ }
+
+ Future<void> test_static_tearoff() async {
+ await resolveTestCode('''
+void f() async {
+ int _ = await g(C.foo);
+}
+
+Future<T> g<T>(Future<T> Function() foo) => foo();
+
+class C {
+}
+''');
+ await assertHasFix('''
+void f() async {
+ int _ = await g(C.foo);
+}
+
+Future<T> g<T>(Future<T> Function() foo) => foo();
+
+class C {
+ static Future<int> foo() async {
+ }
+}
+''');
+ }
+
+ Future<void> test_static_tearoff_prefixed_typeParameter() async {
+ await resolveTestCode('''
+import '' as self;
+
+void f() async {
+ await g(self.C.foo);
+}
+
+Future<T> g<T>(Future<S> Function<S>() foo) => foo();
+
+class C {
+}
+''');
+ await assertHasFix('''
+import '' as self;
+
+void f() async {
+ await g(self.C.foo);
+}
+
+Future<T> g<T>(Future<S> Function<S>() foo) => foo();
+
+class C {
+ static Future<S> foo<S>() async {
+ }
+}
+''');
+ }
+
+ Future<void> test_static_tearoff_prefixed_typeParameter_bound1() async {
+ await resolveTestCode('''
+import '' as self;
+
+void f() async {
+ await g(self.C.foo);
+}
+
+Future<T> g<T>(Future<S> Function<S extends num>() foo) => foo();
+
+class C {
+}
+''');
+ await assertHasFix('''
+import '' as self;
+
+void f() async {
+ await g(self.C.foo);
+}
+
+Future<T> g<T>(Future<S> Function<S extends num>() foo) => foo();
+
+class C {
+ static Future<S> foo<S extends num>() async {
+ }
+}
+''');
+ }
+
+ Future<void> test_static_tearoff_prefixed_typeParameter_bound2() async {
+ await resolveTestCode('''
+import '' as self;
+
+void f() async {
+ await g(self.C.foo);
+}
+
+Future<T> g<T extends num>(Future<S> Function<S extends T>() foo) => foo();
+
+class C {
+}
+''');
+ await assertHasFix('''
+import '' as self;
+
+void f() async {
+ await g(self.C.foo);
+}
+
+Future<T> g<T extends num>(Future<S> Function<S extends T>() foo) => foo();
+
+class C {
+ static Future<S> foo<S extends num>() async {
+ }
+}
+''');
+ }
+
+ Future<void> test_static_tearoff_prefixed_typeParameter_class() async {
+ await resolveTestCode('''
+import '' as self;
+
+void f() async {
+ await g(self.C.foo);
+}
+
+Future<T> g<T>(Future<S> Function<S>() foo) => foo();
+
+class C<S> {
+}
+''');
+ await assertHasFix('''
+import '' as self;
+
+void f() async {
+ await g(self.C.foo);
+}
+
+Future<T> g<T>(Future<S> Function<S>() foo) => foo();
+
+class C<S> {
+ static Future<S> foo<S>() async {
+ }
+}
+''');
+ }
+}
+
+@reflectiveTest
class CreateMethodTest extends FixProcessorTest {
@override
FixKind get kind => DartFixKind.CREATE_METHOD;
@@ -988,114 +1516,6 @@
''');
}
- Future<void> test_enum_tearoff() async {
- await resolveTestCode('''
-enum E {
- e1,
- e2;
-}
-
-void g(int Function() f) {}
-
-void test(E e) {
- g(e.bar);
-}
-''');
- await assertHasFix('''
-enum E {
- e1,
- e2;
- int bar() {
- }
-}
-
-void g(int Function() f) {}
-
-void test(E e) {
- g(e.bar);
-}
-''');
- }
-
- Future<void> test_enum_tearoff_static() async {
- await resolveTestCode('''
-enum E {
- e1,
- e2;
-}
-
-void g(int Function() f) {}
-
-void test() {
- g(E.bar);
-}
-''');
- await assertHasFix('''
-enum E {
- e1,
- e2;
- static int bar() {
- }
-}
-
-void g(int Function() f) {}
-
-void test() {
- g(E.bar);
-}
-''');
- }
-
- Future<void> test_extensionType_tearoff() async {
- await resolveTestCode('''
-extension type E(int i) {
-}
-
-void g(int Function() f) {}
-
-void test(E e) {
- g(e.bar);
-}
-''');
- await assertHasFix('''
-extension type E(int i) {
- int bar() {
- }
-}
-
-void g(int Function() f) {}
-
-void test(E e) {
- g(e.bar);
-}
-''');
- }
-
- Future<void> test_extensionType_tearoff_static() async {
- await resolveTestCode('''
-extension type E(int i) {
-}
-
-void g(int Function() f) {}
-
-void test() {
- g(E.bar);
-}
-''');
- await assertHasFix('''
-extension type E(int i) {
- static int bar() {
- }
-}
-
-void g(int Function() f) {}
-
-void test() {
- g(E.bar);
-}
-''');
- }
-
Future<void> test_functionType_argument() async {
await resolveTestCode('''
class A {
@@ -1116,96 +1536,6 @@
assertLinkedGroup(groups[index++], ['param0']);
}
- Future<void> test_functionType_method_enclosingClass_instance() async {
- await resolveTestCode('''
-class C {
- void m1() {
- m2(m3);
- }
-
- void m2(int Function(int) f) {}
-}
-''');
- await assertHasFix('''
-class C {
- void m1() {
- m2(m3);
- }
-
- void m2(int Function(int) f) {}
-
- int m3(int p1) {
- }
-}
-''');
- }
-
- Future<void> test_functionType_method_enclosingClass_static() async {
- await resolveTestCode('''
-class A {
- static foo() {
- useFunction(test);
- }
-}
-useFunction(int g(double a, String b)) {}
-''');
- await assertHasFix('''
-class A {
- static foo() {
- useFunction(test);
- }
-
- static int test(double a, String b) {
- }
-}
-useFunction(int g(double a, String b)) {}
-''');
- }
-
- Future<void> test_functionType_method_enclosingClass_static2() async {
- await resolveTestCode('''
-class A {
- var f;
- A() : f = useFunction(test);
-}
-useFunction(int g(double a, String b)) {}
-''');
- await assertHasFix('''
-class A {
- var f;
- A() : f = useFunction(test);
-
- static int test(double a, String b) {
- }
-}
-useFunction(int g(double a, String b)) {}
-''');
- }
-
- Future<void> test_functionType_method_FunctionCall() async {
- await resolveTestCode('''
-class C {
- void m1(int i) {
- m2(m3);
- }
-
- void m2(int Function() f) {}
-}
-''');
- await assertHasFix('''
-class C {
- void m1(int i) {
- m2(m3);
- }
-
- void m2(int Function() f) {}
-
- int m3() {
- }
-}
-''');
- }
-
Future<void>
test_functionType_method_inside_conditional_operator_condition() async {
await resolveTestCode('''
@@ -1245,31 +1575,6 @@
}
Future<void>
- test_functionType_method_inside_conditional_operator_else() async {
- await resolveTestCode('''
-class C {
- void m1(int i) {
- m2(i == 0 ? (v) => v : m3);
- }
-
- void m2(int Function(int) f) {}
-}
-''');
- await assertHasFix('''
-class C {
- void m1(int i) {
- m2(i == 0 ? (v) => v : m3);
- }
-
- void m2(int Function(int) f) {}
-
- int m3(int p1) {
- }
-}
-''');
- }
-
- Future<void>
test_functionType_method_inside_conditional_operator_else_FunctionCall() async {
await resolveTestCode('''
class C {
@@ -1294,31 +1599,6 @@
}
Future<void>
- test_functionType_method_inside_conditional_operator_then() async {
- await resolveTestCode('''
-class C {
- void m1(int i) {
- m2(i == 0 ? m3 : (v) => v);
- }
-
- void m2(int Function(int) f) {}
-}
-''');
- await assertHasFix('''
-class C {
- void m1(int i) {
- m2(i == 0 ? m3 : (v) => v);
- }
-
- void m2(int Function(int) f) {}
-
- int m3(int p1) {
- }
-}
-''');
- }
-
- Future<void>
test_functionType_method_inside_conditional_operator_then_FunctionCall() async {
await resolveTestCode('''
class C {
@@ -1342,100 +1622,6 @@
''');
}
- Future<void> test_functionType_method_inside_record_functionType() async {
- await resolveTestCode('''
-class C {
- void m1(int i) {
- m2((m3,));
- }
-
- void m2((int Function(int),) f) {}
-}
-''');
- await assertHasFix('''
-class C {
- void m1(int i) {
- m2((m3,));
- }
-
- void m2((int Function(int),) f) {}
-
- int m3(int p1) {
- }
-}
-''');
- }
-
- Future<void>
- test_functionType_method_inside_record_functionType_named() async {
- await resolveTestCode('''
-class C {
- void m1(int i) {
- m2((f: m3));
- }
-
- void m2(({int Function(int) f}) f) {}
-}
-''');
- await assertHasFix('''
-class C {
- void m1(int i) {
- m2((f: m3));
- }
-
- void m2(({int Function(int) f}) f) {}
-
- int m3(int p1) {
- }
-}
-''');
- }
-
- Future<void> test_functionType_method_targetClass() async {
- await resolveTestCode('''
-void f(A a) {
- useFunction(a.test);
-}
-class A {
-}
-useFunction(int g(double a, String b)) {}
-''');
- await assertHasFix('''
-void f(A a) {
- useFunction(a.test);
-}
-class A {
- int test(double a, String b) {
- }
-}
-useFunction(int g(double a, String b)) {}
-''');
- }
-
- Future<void> test_functionType_method_targetClass_hasOtherMember() async {
- await resolveTestCode('''
-void f(A a) {
- useFunction(a.test);
-}
-class A {
- m() {}
-}
-useFunction(int g(double a, String b)) {}
-''');
- await assertHasFix('''
-void f(A a) {
- useFunction(a.test);
-}
-class A {
- m() {}
-
- int test(double a, String b) {
- }
-}
-useFunction(int g(double a, String b)) {}
-''');
- }
-
Future<void> test_functionType_notFunctionType() async {
await resolveTestCode('''
void f(A a) {
@@ -1829,38 +2015,6 @@
''');
}
- Future<void> test_record_named_tearoff() async {
- await resolveTestCode('''
-class A {
- ({bool Function() fn,}) m() => (fn: m2,);
-}
-''');
- await assertHasFix('''
-class A {
- ({bool Function() fn,}) m() => (fn: m2,);
-
- bool m2() {
- }
-}
-''');
- }
-
- Future<void> test_record_tearoff() async {
- await resolveTestCode('''
-class A {
- (bool Function(),) m() => (m2,);
-}
-''');
- await assertHasFix('''
-class A {
- (bool Function(),) m() => (m2,);
-
- bool m2() {
- }
-}
-''');
- }
-
Future<void> test_returnType_closure_expression() async {
await resolveTestCode('''
class A {
@@ -1914,145 +2068,4 @@
// This should be handled by create extension member fixes
await assertNoFix();
}
-
- Future<void> test_static_tearoff() async {
- await resolveTestCode('''
-void f() async {
- int _ = await g(C.foo);
-}
-
-Future<T> g<T>(Future<T> Function() foo) => foo();
-
-class C {
-}
-''');
- await assertHasFix('''
-void f() async {
- int _ = await g(C.foo);
-}
-
-Future<T> g<T>(Future<T> Function() foo) => foo();
-
-class C {
- static Future<int> foo() async {
- }
-}
-''');
- }
-
- Future<void> test_static_tearoff_prefixed_typeParameter() async {
- await resolveTestCode('''
-import '' as self;
-
-void f() async {
- await g(self.C.foo);
-}
-
-Future<T> g<T>(Future<S> Function<S>() foo) => foo();
-
-class C {
-}
-''');
- await assertHasFix('''
-import '' as self;
-
-void f() async {
- await g(self.C.foo);
-}
-
-Future<T> g<T>(Future<S> Function<S>() foo) => foo();
-
-class C {
- static Future<S> foo<S>() async {
- }
-}
-''');
- }
-
- Future<void> test_static_tearoff_prefixed_typeParameter_bound1() async {
- await resolveTestCode('''
-import '' as self;
-
-void f() async {
- await g(self.C.foo);
-}
-
-Future<T> g<T>(Future<S> Function<S extends num>() foo) => foo();
-
-class C {
-}
-''');
- await assertHasFix('''
-import '' as self;
-
-void f() async {
- await g(self.C.foo);
-}
-
-Future<T> g<T>(Future<S> Function<S extends num>() foo) => foo();
-
-class C {
- static Future<S> foo<S extends num>() async {
- }
-}
-''');
- }
-
- Future<void> test_static_tearoff_prefixed_typeParameter_bound2() async {
- await resolveTestCode('''
-import '' as self;
-
-void f() async {
- await g(self.C.foo);
-}
-
-Future<T> g<T extends num>(Future<S> Function<S extends T>() foo) => foo();
-
-class C {
-}
-''');
- await assertHasFix('''
-import '' as self;
-
-void f() async {
- await g(self.C.foo);
-}
-
-Future<T> g<T extends num>(Future<S> Function<S extends T>() foo) => foo();
-
-class C {
- static Future<S> foo<S extends num>() async {
- }
-}
-''');
- }
-
- Future<void> test_static_tearoff_prefixed_typeParameter_class() async {
- await resolveTestCode('''
-import '' as self;
-
-void f() async {
- await g(self.C.foo);
-}
-
-Future<T> g<T>(Future<S> Function<S>() foo) => foo();
-
-class C<S> {
-}
-''');
- await assertHasFix('''
-import '' as self;
-
-void f() async {
- await g(self.C.foo);
-}
-
-Future<T> g<T>(Future<S> Function<S>() foo) => foo();
-
-class C<S> {
- static Future<S> foo<S>() async {
- }
-}
-''');
- }
}