Skip to content

Commit f702c93

Browse files
jensjohaCommit Queue
authored andcommitted
[analysis server] Sort members more consistant
I ran into an issue (in a child CL) where I couldn't satisfy the sort test because it kept changing the ordering of "p" and "P" because the sorting does `.toLowerCase` before comparing. In this CL - when the result of comparing with a `.toLowerCase` is 0 it compares without the `.toLowerCase` call. Change-Id: Ieed0f199cb61ea45d475c5271a127fbf4463edb7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/413420 Commit-Queue: Jens Johansen <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent dfb20b1 commit f702c93

File tree

4 files changed

+43
-35
lines changed

4 files changed

+43
-35
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,15 @@ class MemberSorter {
6969
// sort all other members by name
7070
var name1 = o1.name.toLowerCase();
7171
var name = o2.name.toLowerCase();
72-
return name1.compareTo(name);
72+
var result = name1.compareTo(name);
73+
if (result == 0) {
74+
result = o1.name.compareTo(o2.name);
75+
}
76+
if (result == 0) {
77+
// don't reorder then.
78+
result = o1.offset - o2.offset;
79+
}
80+
return result;
7381
}
7482
return priority1 - priority2;
7583
});

pkg/analyzer/test/generated/non_error_resolver_test.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,19 +1126,19 @@ Iterable<int> f() sync* {
11261126
''');
11271127
}
11281128

1129-
test_extraPositionalArguments_function() async {
1129+
test_extraPositionalArguments_Function() async {
11301130
await assertNoErrorsInCode(r'''
1131-
f(p1, p2) {}
1132-
main() {
1133-
f(1, 2);
1131+
f(Function a) {
1132+
a(1, 2);
11341133
}
11351134
''');
11361135
}
11371136

1138-
test_extraPositionalArguments_Function() async {
1137+
test_extraPositionalArguments_function() async {
11391138
await assertNoErrorsInCode(r'''
1140-
f(Function a) {
1141-
a(1, 2);
1139+
f(p1, p2) {}
1140+
main() {
1141+
f(1, 2);
11421142
}
11431143
''');
11441144
}

pkg/analyzer/test/src/dart/ast/ast_test.dart

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,24 +1025,24 @@ class IntegerLiteralImplTest {
10251025
false);
10261026
}
10271027

1028-
test_isValidAsInteger_hex_negative_equalMax() {
1029-
expect(
1030-
IntegerLiteralImpl.isValidAsInteger('0x8000000000000000', true), true);
1031-
}
1032-
10331028
test_isValidAsInteger_heX_negative_equalMax() {
10341029
expect(
10351030
IntegerLiteralImpl.isValidAsInteger('0X8000000000000000', true), true);
10361031
}
10371032

1038-
test_isValidAsInteger_hex_negative_fewDigits() {
1039-
expect(IntegerLiteralImpl.isValidAsInteger('0xFF', true), true);
1033+
test_isValidAsInteger_hex_negative_equalMax() {
1034+
expect(
1035+
IntegerLiteralImpl.isValidAsInteger('0x8000000000000000', true), true);
10401036
}
10411037

10421038
test_isValidAsInteger_heX_negative_fewDigits() {
10431039
expect(IntegerLiteralImpl.isValidAsInteger('0XFF', true), true);
10441040
}
10451041

1042+
test_isValidAsInteger_hex_negative_fewDigits() {
1043+
expect(IntegerLiteralImpl.isValidAsInteger('0xFF', true), true);
1044+
}
1045+
10461046
test_isValidAsInteger_heX_negative_leadingZeros_overMax() {
10471047
expect(IntegerLiteralImpl.isValidAsInteger('0X00FFFFFFFFFFFFFFFFF', true),
10481048
false);
@@ -1053,46 +1053,46 @@ class IntegerLiteralImplTest {
10531053
false);
10541054
}
10551055

1056-
test_isValidAsInteger_hex_negative_leadingZeros_underMax() {
1057-
expect(IntegerLiteralImpl.isValidAsInteger('0x007FFFFFFFFFFFFFFF', true),
1058-
true);
1059-
}
1060-
10611056
test_isValidAsInteger_heX_negative_leadingZeros_underMax() {
10621057
expect(IntegerLiteralImpl.isValidAsInteger('0X007FFFFFFFFFFFFFFF', true),
10631058
true);
10641059
}
10651060

1066-
test_isValidAsInteger_hex_negative_oneBelowMax() {
1067-
expect(
1068-
IntegerLiteralImpl.isValidAsInteger('0x7FFFFFFFFFFFFFFF', true), true);
1061+
test_isValidAsInteger_hex_negative_leadingZeros_underMax() {
1062+
expect(IntegerLiteralImpl.isValidAsInteger('0x007FFFFFFFFFFFFFFF', true),
1063+
true);
10691064
}
10701065

10711066
test_isValidAsInteger_heX_negative_oneBelowMax() {
10721067
expect(
10731068
IntegerLiteralImpl.isValidAsInteger('0X7FFFFFFFFFFFFFFF', true), true);
10741069
}
10751070

1076-
test_isValidAsInteger_hex_negative_oneOverMax() {
1071+
test_isValidAsInteger_hex_negative_oneBelowMax() {
10771072
expect(
1078-
IntegerLiteralImpl.isValidAsInteger('0x8000000000000001', true), false);
1073+
IntegerLiteralImpl.isValidAsInteger('0x7FFFFFFFFFFFFFFF', true), true);
10791074
}
10801075

10811076
test_isValidAsInteger_heX_negative_oneOverMax() {
10821077
expect(
10831078
IntegerLiteralImpl.isValidAsInteger('0X8000000000000001', true), false);
10841079
}
10851080

1086-
test_isValidAsInteger_hex_negative_tooManyDigits() {
1087-
expect(IntegerLiteralImpl.isValidAsInteger('0x10000000000000000', true),
1088-
false);
1081+
test_isValidAsInteger_hex_negative_oneOverMax() {
1082+
expect(
1083+
IntegerLiteralImpl.isValidAsInteger('0x8000000000000001', true), false);
10891084
}
10901085

10911086
test_isValidAsInteger_heX_negative_tooManyDigits() {
10921087
expect(IntegerLiteralImpl.isValidAsInteger('0X10000000000000000', true),
10931088
false);
10941089
}
10951090

1091+
test_isValidAsInteger_hex_negative_tooManyDigits() {
1092+
expect(IntegerLiteralImpl.isValidAsInteger('0x10000000000000000', true),
1093+
false);
1094+
}
1095+
10961096
test_isValidAsInteger_heX_positive_equalMax() {
10971097
expect(
10981098
IntegerLiteralImpl.isValidAsInteger('0X7FFFFFFFFFFFFFFF', false), true);
@@ -1141,13 +1141,13 @@ class IntegerLiteralImplTest {
11411141
false);
11421142
}
11431143

1144-
test_isValidAsInteger_hex_positive_tooManyDigits() {
1145-
expect(IntegerLiteralImpl.isValidAsInteger('0xFF0000000000000000', false),
1144+
test_isValidAsInteger_heX_positive_tooManyDigits() {
1145+
expect(IntegerLiteralImpl.isValidAsInteger('0XFF0000000000000000', false),
11461146
false);
11471147
}
11481148

1149-
test_isValidAsInteger_heX_positive_tooManyDigits() {
1150-
expect(IntegerLiteralImpl.isValidAsInteger('0XFF0000000000000000', false),
1149+
test_isValidAsInteger_hex_positive_tooManyDigits() {
1150+
expect(IntegerLiteralImpl.isValidAsInteger('0xFF0000000000000000', false),
11511151
false);
11521152
}
11531153
}

pkg/linter/lib/src/ast.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,14 @@ bool isInPublicDir(CompilationUnit node, WorkspacePackage? package) {
173173
cuPath == linkHookFile;
174174
}
175175

176+
/// Returns `true` if the given [id] is a Dart keyword.
177+
bool isKeyWord(String id) => Keyword.keywords.containsKey(id);
178+
176179
/// Returns `true` if the keyword associated with the given [token] matches
177180
/// [keyword].
178181
bool isKeyword(Token token, Keyword keyword) =>
179182
token is KeywordToken && token.keyword == keyword;
180183

181-
/// Returns `true` if the given [id] is a Dart keyword.
182-
bool isKeyWord(String id) => Keyword.keywords.containsKey(id);
183-
184184
/// Returns `true` if the given [ClassMember] is a method.
185185
bool isMethod(ClassMember m) => m is MethodDeclaration;
186186

0 commit comments

Comments
 (0)