mirror of
https://github.com/dart-lang/sdk
synced 2024-10-06 13:57:58 +00:00
analysis_server: quick fixes for records
* allow rename_to_camel_case to apply to record type field names * allow replace_final_with_const to apply to record literals. Change-Id: Id373180dae9f7a78677e30c4dbc535bbb87ce3f8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/272486 Commit-Queue: Samuel Rawlins <srawlins@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
c9a3327c26
commit
315ff0b8a2
|
@ -43,8 +43,21 @@ class RenameToCamelCase extends CorrectionProducer {
|
|||
} else if (node is VariableDeclaration) {
|
||||
nameToken = node.name;
|
||||
element = node.declaredElement;
|
||||
} else if (node is RecordTypeAnnotationField) {
|
||||
// RecordTypeAnnotationFields do not have Elements.
|
||||
nameToken = node.name;
|
||||
var newName = nameToken?.lexeme.toLowerCamelCase;
|
||||
if (newName == null) {
|
||||
return;
|
||||
}
|
||||
_newName = newName;
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
builder.addSimpleReplacement(range.token(nameToken!), _newName);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (nameToken == null || element == null) {
|
||||
|
||||
if (nameToken == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -54,6 +67,9 @@ class RenameToCamelCase extends CorrectionProducer {
|
|||
return;
|
||||
}
|
||||
_newName = newName;
|
||||
if (element == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Find references to the identifier.
|
||||
List<SimpleIdentifier>? references;
|
||||
|
|
|
@ -153,6 +153,15 @@ void f([int? my_integer_variable]) {
|
|||
void f([int? myIntegerVariable]) {
|
||||
print(myIntegerVariable);
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_recordField() async {
|
||||
await resolveTestCode('''
|
||||
void f(({int some_field}) p) {}
|
||||
''');
|
||||
await assertHasFix('''
|
||||
void f(({int someField}) p) {}
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,6 +80,33 @@ const b = [];
|
|||
''');
|
||||
}
|
||||
|
||||
Future<void> test_emptyRecordLiteral() async {
|
||||
await resolveTestCode('''
|
||||
final () a = ();
|
||||
''');
|
||||
await assertHasFix('''
|
||||
const () a = ();
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_recordLiteral() async {
|
||||
await resolveTestCode('''
|
||||
final (int, int) a = (1, 2);
|
||||
''');
|
||||
await assertHasFix('''
|
||||
const (int, int) a = (1, 2);
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_recordLiteral_nonConst() async {
|
||||
await resolveTestCode('''
|
||||
void f(int a) {
|
||||
final (int, int) r = (a, a);
|
||||
}
|
||||
''');
|
||||
await assertNoFix();
|
||||
}
|
||||
|
||||
Future<void> test_variable() async {
|
||||
await resolveTestCode('''
|
||||
final int a = 1;
|
||||
|
|
Loading…
Reference in a new issue