Skip to content

Commit 29918a5

Browse files
author
Dart CI
committed
Version 3.12.0-67.0.dev
Merge 7c60da7 into dev
2 parents 416f1ef + 7c60da7 commit 29918a5

42 files changed

Lines changed: 358 additions & 421 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

DEPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ vars = {
131131
# and land the review.
132132
#
133133
# For more details, see https://github.com/dart-lang/sdk/issues/30164.
134-
"dart_style_rev": "bdae98cead73a436920f890626aa81cf3f2f8904", # rolled manually
134+
"dart_style_rev": "f624489a5013ec58de469d4fd8793c283f62b5d8", # rolled manually
135135

136136
### /third_party/pkg dependencies
137137
# 'tools/rev_sdk_deps.dart' will rev pkg dependencies to their latest; put an

pkg/analysis_server/lib/src/services/correction/dart/convert_class_to_enum.dart

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ import '../../../utilities/extensions/ast.dart';
2626

2727
typedef _Constructors = Map<ConstructorElement, _Constructor>;
2828

29+
/// This correction producer converts a class to an enum, if possible, by making
30+
/// the following changes:
31+
///
32+
/// * changes the `class` keyword to `enum`,
33+
/// * removes the `const` keyword from the primary constructor, if there is one,
34+
/// * converts static fields into enum constant values,
35+
/// * removes an `int index` field if there is one,
36+
/// * removes any field formal parameters for the index field from all
37+
/// constructors,
38+
/// * removes all arguments for said index field formal parameters,
39+
/// * removes the singular constructor (primary, or in-body), if there is only
40+
/// one, and it no longer accepts any arguments (after removing a possible
41+
/// index parameter), and it has no doc comment nor annotations.
2942
class ConvertClassToEnum extends ResolvedCorrectionProducer {
3043
ConvertClassToEnum({required super.context});
3144

@@ -160,6 +173,9 @@ class _EnumDescription {
160173
/// The indexes of members that need to be deleted.
161174
final List<int> membersToDelete = [];
162175

176+
/// The primary constructor, if it needs to be deleted.
177+
PrimaryConstructorDeclaration? primaryConstructorToDelete;
178+
163179
/// The indexes of primary constructor parameters that need to be deleted.
164180
final List<int> parametersToDelete = [];
165181

@@ -287,6 +303,14 @@ class _EnumDescription {
287303
// Update the constructors.
288304
_transformConstructors(builder);
289305

306+
if (primaryConstructorToDelete case var primaryConstructor?) {
307+
if (primaryConstructor.constructorName case var constuctorName?) {
308+
builder.addDeletion(range.startEnd(constuctorName, primaryConstructor));
309+
} else {
310+
builder.addDeletion(range.node(primaryConstructor.formalParameters));
311+
}
312+
}
313+
290314
// Special case replacing all of the members.
291315
if (membersToDelete.length == members.length) {
292316
builder.addSimpleReplacement(
@@ -390,7 +414,7 @@ class _EnumDescription {
390414
parameters.length - (parameterData == null ? 0 : 1);
391415
if (updatedParameterCount != 0) return null;
392416

393-
// TODO(srawlins): Mark `primaryConstructor` as "to be deleted."
417+
primaryConstructorToDelete = primaryConstructor;
394418
return primaryConstructor;
395419
}
396420
}

pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3065,10 +3065,6 @@ missing_star_after_sync:
30653065
Remove the `sync` keyword. Add a `*`.
30663066
missing_statement:
30673067
status: noFix
3068-
missing_terminator_for_parameter_group:
3069-
status: needsFix
3070-
notes: |-
3071-
Add the missing terminator.
30723068
missing_typedef_parameters:
30733069
status: hasFix
30743070
missing_variable_in_for_each:
@@ -3116,8 +3112,6 @@ multiple_representation_fields:
31163112
notes: |-
31173113
Remove extra fields.
31183114
Maybe wrap into a record.
3119-
multiple_variables_in_for_each:
3120-
status: noFix
31213115
multiple_variance_modifiers:
31223116
status: noFix
31233117
multiple_with_clauses:
@@ -3158,8 +3152,6 @@ non_part_of_directive_in_part:
31583152
Remove the directive. Move the directive to the library.
31593153
non_string_literal_as_uri:
31603154
status: noFix
3161-
non_user_definable_operator:
3162-
status: noFix
31633155
normal_before_optional_parameters:
31643156
status: needsFix
31653157
notes: |-
@@ -3268,10 +3260,6 @@ typedef_in_class:
32683260
status: needsFix
32693261
notes: |-
32703262
Move the typedef to the top level.
3271-
unexpected_terminator_for_parameter_group:
3272-
status: needsFix
3273-
notes: |-
3274-
Remove the terminator.
32753263
unexpected_token:
32763264
status: noFix
32773265
unexpected_tokens:
@@ -3308,10 +3296,6 @@ wrong_number_of_parameters_for_setter:
33083296
status: needsFix
33093297
wrong_separator_for_positional_parameter:
33103298
status: hasFix
3311-
wrong_terminator_for_parameter_group:
3312-
status: needsFix
3313-
notes: |-
3314-
Replace the terminator with the correct terminator.
33153299
asset_does_not_exist:
33163300
status: noFix
33173301
since: ~2.15
@@ -3390,8 +3374,6 @@ missing_hex_digit:
33903374
status: noFix
33913375
missing_quote:
33923376
status: noFix
3393-
unable_get_content:
3394-
status: noFix
33953377
unexpected_dollar_in_string:
33963378
status: noFix
33973379
unexpected_separator_in_number:

pkg/analysis_server/test/services/refactoring/legacy/extract_widget_test.dart

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ class C {
371371
}
372372
373373
class MyWidget extends StatelessWidget {
374-
C c = C();
374+
final C c = C();
375375
376376
@override
377377
Widget build(BuildContext context) {
@@ -394,7 +394,7 @@ class C {
394394
}
395395
396396
class MyWidget extends StatelessWidget {
397-
C c = C();
397+
final C c = C();
398398
399399
@override
400400
Widget build(BuildContext context) {
@@ -476,7 +476,7 @@ class Test extends StatelessWidget {
476476
import 'package:flutter/material.dart';
477477
478478
class MyWidget extends StatelessWidget {
479-
String foo = '';
479+
final String foo = '';
480480
481481
@override
482482
Widget build(BuildContext context) {
@@ -504,7 +504,7 @@ class MyWidget extends StatelessWidget {
504504
import 'package:flutter/material.dart';
505505
506506
class MyWidget extends StatelessWidget {
507-
String foo = '';
507+
final String foo = '';
508508
509509
@override
510510
Widget build(BuildContext context) {
@@ -720,7 +720,7 @@ class C {
720720
}
721721
722722
class MyWidget extends StatelessWidget {
723-
C c = C();
723+
final C c = C();
724724
725725
@override
726726
Widget build(BuildContext context) {
@@ -738,7 +738,7 @@ class C {
738738
}
739739
740740
class MyWidget extends StatelessWidget {
741-
C c = C();
741+
final C c = C();
742742
743743
@override
744744
Widget build(BuildContext context) {
@@ -806,6 +806,7 @@ class Test extends StatelessWidget {
806806
await indexTestUnit(r'''
807807
import 'package:flutter/material.dart';
808808
809+
// ignore: must_be_immutable
809810
class MyWidget extends StatelessWidget {
810811
String field;
811812
@@ -832,10 +833,12 @@ class MyWidget extends StatelessWidget {
832833
await indexTestUnit(r'''
833834
import 'package:flutter/material.dart';
834835
836+
// ignore: must_be_immutable
835837
abstract class MySuperWidget extends StatelessWidget {
836838
String field = '';
837839
}
838840
841+
// ignore: must_be_immutable
839842
class MyWidget extends MySuperWidget {
840843
@override
841844
Widget build(BuildContext context) {
@@ -863,7 +866,7 @@ class C {
863866
}
864867
865868
class MyWidget extends StatelessWidget {
866-
C c = C();
869+
final C c = C();
867870
868871
@override
869872
Widget build(BuildContext context) {
@@ -886,7 +889,7 @@ class C {
886889
}
887890
888891
class MyWidget extends StatelessWidget {
889-
C c = C();
892+
final C c = C();
890893
891894
@override
892895
Widget build(BuildContext context) {

pkg/analysis_server/test/src/services/correction/assist/add_diagnostic_property_reference_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import 'package:flutter/foundation.dart';
3232
import 'package:flutter/widgets.dart';
3333
3434
class W extends Widget {
35-
bool ^property = true;
35+
final bool ^property = true;
3636
@override
3737
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
3838
super.debugFillProperties(properties);
@@ -44,7 +44,7 @@ import 'package:flutter/foundation.dart';
4444
import 'package:flutter/widgets.dart';
4545
4646
class W extends Widget {
47-
bool property = true;
47+
final bool property = true;
4848
@override
4949
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
5050
super.debugFillProperties(properties);

pkg/analysis_server/test/src/services/correction/assist/convert_class_to_enum_test.dart

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,8 @@ enum _E {
272272
''');
273273
}
274274

275-
@FailingTest(reason: 'To implement next.')
276275
Future<void>
277276
test_index_namedIndex_only_privateClass_primaryConstructor() async {
278-
// TODO(srawlins): Test with primary constructor with non-declaring index
279-
// parameter.
280-
// TODO(srawlins): Test with private primary constructor on a public class.
281277
await resolveTestCode('''
282278
class const _^E(final int index) {
283279
static const _E c0 = _E(0);
@@ -292,6 +288,24 @@ enum _E {
292288
''');
293289
}
294290

291+
Future<void>
292+
test_index_namedIndex_only_privateClass_primaryConstructor_nonDeclaring() async {
293+
await resolveTestCode('''
294+
class const _^E(this.index) {
295+
static const _E c0 = _E(0);
296+
static const _E c1 = _E(1);
297+
298+
final int index;
299+
}
300+
''');
301+
await assertHasAssist('''
302+
enum _E {
303+
c0,
304+
c1
305+
}
306+
''');
307+
}
308+
295309
Future<void> test_index_namedIndex_only_publicClass() async {
296310
await resolveTestCode('''
297311
class ^E {
@@ -313,6 +327,22 @@ enum E {
313327
''');
314328
}
315329

330+
Future<void>
331+
test_index_namedIndex_only_publicClass_primaryConstructor() async {
332+
await resolveTestCode('''
333+
class const ^E._(final int index) {
334+
static const E c0 = E._(0);
335+
static const E c1 = E._(1);
336+
}
337+
''');
338+
await assertHasAssist('''
339+
enum E._() {
340+
c0._(),
341+
c1._()
342+
}
343+
''');
344+
}
345+
316346
Future<void> test_index_notNamedIndex_privateClass() async {
317347
await resolveTestCode('''
318348
class _^E {
@@ -649,6 +679,59 @@ enum _E {
649679
''');
650680
}
651681

682+
Future<void> test_minimal_privateClass_primaryConstructor() async {
683+
await resolveTestCode('''
684+
class const _^E() {
685+
static const _E c = _E();
686+
}
687+
''');
688+
await assertHasAssist('''
689+
enum _E {
690+
c
691+
}
692+
''');
693+
}
694+
695+
Future<void>
696+
test_minimal_privateClass_primaryConstructorHasAnnotation() async {
697+
await resolveTestCode('''
698+
class const _^E() {
699+
static const _E c = _E();
700+
701+
@deprecated
702+
this;
703+
}
704+
''');
705+
await assertHasAssist('''
706+
enum _E() {
707+
c;
708+
709+
@deprecated
710+
this;
711+
}
712+
''');
713+
}
714+
715+
Future<void>
716+
test_minimal_privateClass_primaryConstructorHasDocComment() async {
717+
await resolveTestCode('''
718+
class const _^E() {
719+
static const _E c = _E();
720+
721+
/// Doc comment.
722+
this;
723+
}
724+
''');
725+
await assertHasAssist('''
726+
enum _E() {
727+
c;
728+
729+
/// Doc comment.
730+
this;
731+
}
732+
''');
733+
}
734+
652735
Future<void> test_minimal_publicClass() async {
653736
await resolveTestCode('''
654737
class ^E {

pkg/analysis_server/test/src/services/correction/assist/flutter_convert_to_stateful_widget_test.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ class _MyWidgetState<T> extends State<MyWidget<T>> {
175175
await resolveTestCode(r'''
176176
import 'package:flutter/material.dart';
177177
178+
// ignore: must_be_immutable
178179
class ^MyWidget extends StatelessWidget {
179180
static String staticField1 = '';
180181
final String instanceField1;
@@ -210,6 +211,7 @@ class ^MyWidget extends StatelessWidget {
210211
await assertHasAssist(r'''
211212
import 'package:flutter/material.dart';
212213
214+
// ignore: must_be_immutable
213215
class MyWidget extends StatefulWidget {
214216
static String staticField1 = '';
215217
final String instanceField1;
@@ -316,7 +318,7 @@ import 'package:flutter/material.dart';
316318
class ^MyWidget extends StatelessWidget {
317319
static String staticField = '';
318320
final String instanceField1;
319-
String instanceField2 = '';
321+
final String instanceField2 = '';
320322
321323
MyWidget(this.instanceField1);
322324
@@ -372,7 +374,7 @@ class MyWidget extends StatefulWidget {
372374
}
373375
374376
class _MyWidgetState extends State<MyWidget> {
375-
String instanceField2 = '';
377+
final String instanceField2 = '';
376378
377379
@override
378380
Widget build(BuildContext context) {

0 commit comments

Comments
 (0)