mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 08:44:27 +00:00
add fix for removing the leading underscore from local function names
Closes https://github.com/dart-lang/sdk/pull/52822 GitOrigin-RevId: 1e97f3fde70079ea47a4bb8f8f58db341ae26fdc Change-Id: Iec46cca3532789b4fb338d73cdbb946a0d383845 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312061 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
6022e0eee6
commit
e826300560
2 changed files with 20 additions and 2 deletions
|
@ -42,6 +42,9 @@ class RemoveLeadingUnderscore extends ResolvedCorrectionProducer {
|
|||
} else if (node is DeclaredVariablePattern) {
|
||||
nameToken = node.name;
|
||||
element = node.declaredElement;
|
||||
} else if (node is FunctionDeclaration) {
|
||||
nameToken = node.name;
|
||||
element = node.declaredElement;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
@ -59,10 +62,10 @@ class RemoveLeadingUnderscore extends ResolvedCorrectionProducer {
|
|||
|
||||
// Find references to the identifier.
|
||||
List<SimpleIdentifier>? references;
|
||||
if (element is LocalVariableElement) {
|
||||
if (element is LocalVariableElement || element is FunctionElement) {
|
||||
var block = node.thisOrAncestorOfType<Block>();
|
||||
if (block != null) {
|
||||
references = findLocalElementReferences(block, element);
|
||||
references = findLocalElementReferences(block, element as LocalElement);
|
||||
|
||||
var declaration = block.thisOrAncestorOfType<MethodDeclaration>() ??
|
||||
block.thisOrAncestorOfType<FunctionDeclaration>();
|
||||
|
|
|
@ -89,6 +89,21 @@ f() {
|
|||
''');
|
||||
}
|
||||
|
||||
Future<void> test_localFunction() async {
|
||||
await resolveTestCode(r'''
|
||||
void f() {
|
||||
int _foo() => 1;
|
||||
print(_foo());
|
||||
}
|
||||
''');
|
||||
await assertHasFix('''
|
||||
void f() {
|
||||
int foo() => 1;
|
||||
print(foo());
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_localVariable() async {
|
||||
await resolveTestCode('''
|
||||
void f() {
|
||||
|
|
Loading…
Reference in a new issue