Skip to content

Commit

Permalink
QuickFix. Issue 55804. Don't suggest creating mixin when it is a name…
Browse files Browse the repository at this point in the history
… of property.

Bug: #55804
Change-Id: Ibbdeac3a662ef140fb88e834416f064c899365bf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368681
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
  • Loading branch information
scheglov authored and Commit Queue committed May 29, 2024
1 parent d047d44 commit 04d7213
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@ class CreateMixin extends ResolvedCorrectionProducer {
_mixinName = node.name2.lexeme;
} else if (node is SimpleIdentifier) {
var parent = node.parent;
var grandParent = parent?.parent;
if (parent is NamedType &&
grandParent is ConstructorName &&
grandParent.parent is InstanceCreationExpression) {
return;
} else {
_mixinName = node.name;
switch (parent) {
case PrefixedIdentifier():
if (parent.identifier == node) {
return;
}
case PropertyAccess():
if (parent.propertyName == node) {
return;
}
}
_mixinName = node.name;
} else if (node is PrefixedIdentifier) {
if (node.parent is InstanceCreationExpression) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,45 @@ mixin Test {
assertLinkedGroup(change.linkedEditGroups[0], ['Test])', 'Test {']);
}

Future<void> test_prefixedIdentifier_identifier() async {
await resolveTestCode('''
void f(C c) {
c.test;
}
class C {}
''');
await assertNoFix();
}

Future<void> test_prefixedIdentifier_prefix() async {
await resolveTestCode('''
void f() {
Test.value;
}
''');
await assertHasFix('''
void f() {
Test.value;
}
mixin Test {
}
''');
assertLinkedGroup(change.linkedEditGroups[0], ['Test.value', 'Test {']);
}

Future<void> test_propertyAccess_property() async {
await resolveTestCode('''
void f(C c) {
(c).test;
}
class C {}
''');
await assertNoFix();
}

Future<void> test_simple() async {
await resolveTestCode('''
void f() {
Expand Down

0 comments on commit 04d7213

Please sign in to comment.