mirror of
https://github.com/dart-lang/sdk
synced 2024-09-06 00:59:09 +00:00
QuickFix. Issue 55804. Don't suggest creating local vriable when it is a name of property.
Bug: https://github.com/dart-lang/sdk/issues/55804 Change-Id: Ib61c025855464e1b7f01116234624d936ee9bc89 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368701 Reviewed-by: Phil Quitslund <pquitslund@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
04d7213fe8
commit
28da71b42d
|
@ -44,6 +44,17 @@ class CreateLocalVariable extends ResolvedCorrectionProducer {
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// In `foo.bar`, `bar` is not a local variable.
|
||||
// It also does not seem useful to suggest `foo`.
|
||||
// So, always skip with these parents.
|
||||
var parent = nameNode.parent;
|
||||
switch (parent) {
|
||||
case PrefixedIdentifier():
|
||||
case PropertyAccess():
|
||||
return;
|
||||
}
|
||||
|
||||
// prepare target Statement
|
||||
var target = node.thisOrAncestorOfType<Statement>();
|
||||
if (target == null) {
|
||||
|
|
|
@ -95,13 +95,33 @@ void f() {
|
|||
''');
|
||||
}
|
||||
|
||||
@failingTest
|
||||
Future<void> test_propertyAccess() async {
|
||||
// We should not offer to define a local variable named 'g'.
|
||||
Future<void> test_read_prefixedIdentifier_identifier() async {
|
||||
await resolveTestCode('''
|
||||
void f(String s) {
|
||||
s.g;
|
||||
void f(C c) {
|
||||
c.test;
|
||||
}
|
||||
|
||||
class C {}
|
||||
''');
|
||||
await assertNoFix();
|
||||
}
|
||||
|
||||
Future<void> test_read_prefixedIdentifier_prefix() async {
|
||||
await resolveTestCode('''
|
||||
void f() {
|
||||
test.foo;
|
||||
}
|
||||
''');
|
||||
await assertNoFix();
|
||||
}
|
||||
|
||||
Future<void> test_read_propertyAccess_propertyName() async {
|
||||
await resolveTestCode('''
|
||||
void f(C c) {
|
||||
(c).test;
|
||||
}
|
||||
|
||||
class C {}
|
||||
''');
|
||||
await assertNoFix();
|
||||
}
|
||||
|
@ -287,4 +307,35 @@ void f() {
|
|||
}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_write_prefixedIdentifier_identifier() async {
|
||||
await resolveTestCode('''
|
||||
void f(C c) {
|
||||
c.test = 0;
|
||||
}
|
||||
|
||||
class C {}
|
||||
''');
|
||||
await assertNoFix();
|
||||
}
|
||||
|
||||
Future<void> test_write_prefixedIdentifier_prefix() async {
|
||||
await resolveTestCode('''
|
||||
void f() {
|
||||
test.foo = 0;
|
||||
}
|
||||
''');
|
||||
await assertNoFix();
|
||||
}
|
||||
|
||||
Future<void> test_write_propertyAccess_propertyName() async {
|
||||
await resolveTestCode('''
|
||||
void f(C c) {
|
||||
(c).test = 0;
|
||||
}
|
||||
|
||||
class C {}
|
||||
''');
|
||||
await assertNoFix();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue