mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 03:36:59 +00:00
Add extension type support for create method fix
Bug:49741 Change-Id: I8687dbf3fe0532bd04163a42104bbdddd0d173fb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/331742 Commit-Queue: Keerti Parthasarathy <keertip@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
cecb0cabd6
commit
0323445167
|
@ -339,6 +339,17 @@ abstract class ResolvedCorrectionProducer
|
|||
return null;
|
||||
}
|
||||
|
||||
/// Return the extension type for the given [element].
|
||||
Future<ExtensionTypeDeclaration?> getExtensionTypeDeclaration(
|
||||
ExtensionTypeElement element) async {
|
||||
var result = await sessionHelper.getElementDeclaration(element);
|
||||
var node = result?.node;
|
||||
if (node is ExtensionTypeDeclaration) {
|
||||
return node;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
LinterContext getLinterContext(path.Context pathContext) {
|
||||
return LinterContextImpl(
|
||||
[], // unused
|
||||
|
|
|
@ -160,13 +160,16 @@ class CreateMethod extends ResolvedCorrectionProducer {
|
|||
targetNode = await getMixinDeclaration(targetClassElement);
|
||||
} else if (targetClassElement is ClassElement) {
|
||||
targetNode = await getClassDeclaration(targetClassElement);
|
||||
} else if (targetClassElement is ExtensionTypeElement) {
|
||||
targetNode = await getExtensionTypeDeclaration(targetClassElement);
|
||||
}
|
||||
if (targetNode == null) {
|
||||
return;
|
||||
}
|
||||
// maybe static
|
||||
if (target is Identifier) {
|
||||
staticModifier = target.staticElement?.kind == ElementKind.CLASS;
|
||||
staticModifier = target.staticElement?.kind == ElementKind.CLASS ||
|
||||
target.staticElement?.kind == ElementKind.EXTENSION_TYPE;
|
||||
}
|
||||
// use different utils
|
||||
var targetPath = targetClassElement.source.fullName;
|
||||
|
|
|
@ -263,6 +263,24 @@ void f() {
|
|||
''');
|
||||
}
|
||||
|
||||
Future<void> test_createQualified_fromExtensionType() async {
|
||||
await resolveTestCode('''
|
||||
extension type A(String s) {
|
||||
}
|
||||
void f() {
|
||||
A.myUndefinedMethod();
|
||||
}
|
||||
''');
|
||||
await assertHasFix('''
|
||||
extension type A(String s) {
|
||||
static void myUndefinedMethod() {}
|
||||
}
|
||||
void f() {
|
||||
A.myUndefinedMethod();
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_createQualified_fromInstance() async {
|
||||
await resolveTestCode('''
|
||||
class A {
|
||||
|
@ -281,6 +299,24 @@ void f(A a) {
|
|||
''');
|
||||
}
|
||||
|
||||
Future<void> test_createQualified_instance_fromExtensionType() async {
|
||||
await resolveTestCode('''
|
||||
extension type A(String s) {
|
||||
}
|
||||
void f(A a) {
|
||||
a.myUndefinedMethod();
|
||||
}
|
||||
''');
|
||||
await assertHasFix('''
|
||||
extension type A(String s) {
|
||||
void myUndefinedMethod() {}
|
||||
}
|
||||
void f(A a) {
|
||||
a.myUndefinedMethod();
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_createQualified_targetIsFunctionType() async {
|
||||
await resolveTestCode('''
|
||||
typedef A();
|
||||
|
|
Loading…
Reference in a new issue