Skip to content

Commit 0041431

Browse files
author
Dart CI
committed
Version 2.17.0-95.0.dev
Merge commit '7605a36ab3e1601ee561758fc6936c707c0f90c0' into 'dev'
2 parents a9cfcc2 + 7605a36 commit 0041431

File tree

57 files changed

+7445
-7298
lines changed

Some content is hidden

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

57 files changed

+7445
-7298
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart';
6+
import 'package:analysis_server/src/services/correction/fix.dart';
7+
import 'package:analyzer/dart/ast/ast.dart';
8+
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
9+
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
10+
import 'package:analyzer_plugin/utilities/range_factory.dart';
11+
12+
class SortConstructorFirst extends CorrectionProducer {
13+
@override
14+
bool get canBeAppliedInBulk => true;
15+
16+
@override
17+
bool get canBeAppliedToFile => true;
18+
19+
@override
20+
FixKind get fixKind => DartFixKind.SORT_CONSTRUCTOR_FIRST;
21+
22+
@override
23+
FixKind get multiFixKind => DartFixKind.SORT_CONSTRUCTOR_FIRST_MULTI;
24+
25+
@override
26+
Future<void> compute(ChangeBuilder builder) async {
27+
var constructor = coveredNode?.parent;
28+
var clazz = constructor?.parent;
29+
if (clazz is! ClassDeclaration || constructor is! ConstructorDeclaration) {
30+
return;
31+
}
32+
33+
await builder.addDartFileEdit(file, (builder) {
34+
var deletionRange = range.endEnd(
35+
constructor.beginToken.previous!,
36+
constructor.endToken,
37+
);
38+
39+
builder.addDeletion(deletionRange);
40+
builder.addSimpleInsertion(
41+
clazz.leftBracket.end,
42+
utils.getRangeText(deletionRange),
43+
);
44+
});
45+
}
46+
47+
/// Return an instance of this class. Used as a tear-off in `FixProcessor`.
48+
static SortConstructorFirst newInstance() => SortConstructorFirst();
49+
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,16 @@ class DartFixKind {
14401440
DartFixKindPriority.IN_FILE,
14411441
'Move child properties to ends of arguments everywhere in file',
14421442
);
1443+
static const SORT_CONSTRUCTOR_FIRST = FixKind(
1444+
'dart.fix.sort.sortConstructorFirst',
1445+
DartFixKindPriority.DEFAULT,
1446+
'Move before other members',
1447+
);
1448+
static const SORT_CONSTRUCTOR_FIRST_MULTI = FixKind(
1449+
'dart.fix.sort.sortConstructorFirst.multi',
1450+
DartFixKindPriority.DEFAULT,
1451+
'Move all constructors before other members',
1452+
);
14431453
static const SORT_UNNAMED_CONSTRUCTOR_FIRST = FixKind(
14441454
'dart.fix.sort.sortUnnamedConstructorFirst',
14451455
DartFixKindPriority.DEFAULT,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ import 'package:analysis_server/src/services/correction/dart/replace_with_null_a
170170
import 'package:analysis_server/src/services/correction/dart/replace_with_tear_off.dart';
171171
import 'package:analysis_server/src/services/correction/dart/replace_with_var.dart';
172172
import 'package:analysis_server/src/services/correction/dart/sort_child_property_last.dart';
173+
import 'package:analysis_server/src/services/correction/dart/sort_constructor_first.dart';
173174
import 'package:analysis_server/src/services/correction/dart/sort_unnamed_constructor_first.dart';
174175
import 'package:analysis_server/src/services/correction/dart/update_sdk_constraints.dart';
175176
import 'package:analysis_server/src/services/correction/dart/use_const.dart';
@@ -572,6 +573,9 @@ class FixProcessor extends BaseProcessor {
572573
LintNames.sort_child_properties_last: [
573574
SortChildPropertyLast.newInstance,
574575
],
576+
LintNames.sort_constructors_first: [
577+
SortConstructorFirst.newInstance,
578+
],
575579
LintNames.sort_unnamed_constructors_first: [
576580
SortUnnamedConstructorFirst.newInstance,
577581
],
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analysis_server/src/services/correction/fix.dart';
6+
import 'package:analysis_server/src/services/linter/lint_names.dart';
7+
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
8+
import 'package:test_reflective_loader/test_reflective_loader.dart';
9+
10+
import 'fix_processor.dart';
11+
12+
void main() {
13+
defineReflectiveSuite(() {
14+
defineReflectiveTests(SortConstructorFirstBulkTest);
15+
defineReflectiveTests(SortConstructorFirstTest);
16+
});
17+
}
18+
19+
@reflectiveTest
20+
class SortConstructorFirstBulkTest extends BulkFixProcessorTest {
21+
@override
22+
String get lintCode => LintNames.sort_constructors_first;
23+
24+
Future<void> test_multiple_classes() async {
25+
await resolveTestCode('''
26+
class A {
27+
X() {}
28+
A();
29+
}
30+
31+
class B {
32+
Y() {}
33+
B();
34+
}
35+
''');
36+
await assertHasFix('''
37+
class A {
38+
A();
39+
X() {}
40+
}
41+
42+
class B {
43+
B();
44+
Y() {}
45+
}
46+
''');
47+
}
48+
49+
Future<void> test_single_class() async {
50+
await resolveTestCode('''
51+
class A {
52+
X() {}
53+
54+
A();
55+
56+
Y() {}
57+
58+
A._();
59+
}
60+
''');
61+
await assertHasFix('''
62+
class A {
63+
64+
A();
65+
66+
A._();
67+
X() {}
68+
69+
Y() {}
70+
}
71+
''');
72+
}
73+
}
74+
75+
@reflectiveTest
76+
class SortConstructorFirstTest extends FixProcessorLintTest {
77+
@override
78+
FixKind get kind => DartFixKind.SORT_CONSTRUCTOR_FIRST;
79+
80+
@override
81+
String get lintCode => LintNames.sort_constructors_first;
82+
83+
Future<void> test_one_fix() async {
84+
await resolveTestCode('''
85+
class A {
86+
X() {}
87+
A();
88+
}
89+
''');
90+
await assertHasFix('''
91+
class A {
92+
A();
93+
X() {}
94+
}
95+
''');
96+
}
97+
}

pkg/analysis_server/test/src/services/correction/fix/test_all.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ import 'replace_with_null_aware_test.dart' as replace_with_null_aware;
207207
import 'replace_with_tear_off_test.dart' as replace_with_tear_off;
208208
import 'replace_with_var_test.dart' as replace_with_var;
209209
import 'sort_child_property_last_test.dart' as sort_properties_last;
210+
import 'sort_constructor_first_test.dart' as sort_constructor_first_test;
210211
import 'sort_unnamed_constructor_first_test.dart'
211212
as sort_unnamed_constructor_first_test;
212213
import 'update_sdk_constraints_test.dart' as update_sdk_constraints;
@@ -400,6 +401,7 @@ void main() {
400401
replace_with_tear_off.main();
401402
replace_with_var.main();
402403
sort_properties_last.main();
404+
sort_constructor_first_test.main();
403405
sort_unnamed_constructor_first_test.main();
404406
update_sdk_constraints.main();
405407
use_const.main();

pkg/analyzer/lib/src/dart/constant/constant_verifier.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ class ConstantVerifier extends RecursiveAstVisitor<void> {
623623
.NON_CONSTANT_CASE_EXPRESSION_FROM_DEFERRED_LIBRARY,
624624
);
625625

626-
var expressionValueType = _typeSystem.toLegacyType(
626+
var expressionValueType = _typeSystem.toLegacyTypeIfOptOut(
627627
expressionValue.type,
628628
);
629629

pkg/analyzer/lib/src/dart/constant/evaluation.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2605,7 +2605,7 @@ extension RuntimeExtensions on TypeSystemImpl {
26052605
DartType type,
26062606
) {
26072607
if (!isNonNullableByDefault) {
2608-
type = toLegacyType(type);
2608+
type = toLegacyTypeIfOptOut(type);
26092609
}
26102610
var objType = obj.type;
26112611
return isSubtypeOf(objType, type);

pkg/analyzer/lib/src/dart/element/class_hierarchy.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class _ClassInterfaceType {
183183
);
184184
}
185185
} else {
186-
var legacyType = _typeSystem.toLegacyType(type) as InterfaceType;
186+
var legacyType = _typeSystem.toLegacyTypeIfOptOut(type) as InterfaceType;
187187
if (_currentResult == null) {
188188
_currentResult = legacyType;
189189
} else {

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,9 +1364,6 @@ class ConstructorElementImpl extends ExecutableElementImpl
13641364
setModifier(Modifier.FACTORY, isFactory);
13651365
}
13661366

1367-
@override
1368-
bool get isStatic => false;
1369-
13701367
@override
13711368
ElementKind get kind => ElementKind.CONSTRUCTOR;
13721369

@@ -2879,6 +2876,15 @@ abstract class ExecutableElementImpl extends _ExistingElementImpl
28792876
@override
28802877
bool get isOperator => false;
28812878

2879+
@override
2880+
bool get isStatic {
2881+
return hasModifier(Modifier.STATIC);
2882+
}
2883+
2884+
set isStatic(bool isStatic) {
2885+
setModifier(Modifier.STATIC, isStatic);
2886+
}
2887+
28822888
@override
28832889
bool get isSynchronous => !isAsynchronous;
28842890

@@ -3250,16 +3256,6 @@ class FieldElementImpl extends PropertyInducingElementImpl
32503256
return hasModifier(Modifier.EXTERNAL);
32513257
}
32523258

3253-
@override
3254-
bool get isStatic {
3255-
return hasModifier(Modifier.STATIC);
3256-
}
3257-
3258-
/// Set whether this field is static.
3259-
set isStatic(bool isStatic) {
3260-
setModifier(Modifier.STATIC, isStatic);
3261-
}
3262-
32633259
/// Return `true` if this element is a synthetic enum field.
32643260
///
32653261
/// It is synthetic because it is not written explicitly in code, but it
@@ -3352,9 +3348,6 @@ class FunctionElementImpl extends ExecutableElementImpl
33523348
return isStatic && displayName == FunctionElement.MAIN_FUNCTION_NAME;
33533349
}
33543350

3355-
@override
3356-
bool get isStatic => enclosingElement is CompilationUnitElement;
3357-
33583351
@override
33593352
ElementKind get kind => ElementKind.FUNCTION;
33603353

@@ -4208,16 +4201,6 @@ class MethodElementImpl extends ExecutableElementImpl implements MethodElement {
42084201
first == 0x24);
42094202
}
42104203

4211-
@override
4212-
bool get isStatic {
4213-
return hasModifier(Modifier.STATIC);
4214-
}
4215-
4216-
/// Set whether this method is static.
4217-
set isStatic(bool isStatic) {
4218-
setModifier(Modifier.STATIC, isStatic);
4219-
}
4220-
42214204
@override
42224205
ElementKind get kind => ElementKind.METHOD;
42234206

@@ -5047,16 +5030,6 @@ class PropertyAccessorElementImpl extends ExecutableElementImpl
50475030
setModifier(Modifier.SETTER, isSetter);
50485031
}
50495032

5050-
@override
5051-
bool get isStatic {
5052-
return hasModifier(Modifier.STATIC);
5053-
}
5054-
5055-
/// Set whether this accessor is static.
5056-
set isStatic(bool isStatic) {
5057-
setModifier(Modifier.STATIC, isStatic);
5058-
}
5059-
50605033
@override
50615034
ElementKind get kind {
50625035
if (isGetter) {
@@ -5931,6 +5904,10 @@ abstract class VariableElementImpl extends ElementImpl
59315904
@override
59325905
bool get isStatic => hasModifier(Modifier.STATIC);
59335906

5907+
set isStatic(bool isStatic) {
5908+
setModifier(Modifier.STATIC, isStatic);
5909+
}
5910+
59345911
@override
59355912
String get name => super.name!;
59365913

pkg/analyzer/lib/src/dart/element/least_upper_bound.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class InterfaceLeastUpperBoundHelper {
248248
return result;
249249
} else {
250250
return result.map((e) {
251-
return e.mapArguments(typeSystem.toLegacyType);
251+
return e.mapArguments(typeSystem.toLegacyTypeIfOptOut);
252252
}).toSet();
253253
}
254254
}

0 commit comments

Comments
 (0)