Extension types. Support for sorting.

Change-Id: I632b05f9e02283eca663e68d6087230182003e97
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/323425
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
This commit is contained in:
Konstantin Shcheglov 2023-08-30 18:55:31 +00:00
parent 5d3d43bf2d
commit f722afcf0c
2 changed files with 218 additions and 0 deletions

View file

@ -28,6 +28,8 @@ class MemberSorter {
_PriorityItem(false, _MemberKind.UNIT_FUNCTION_TYPE, true),
_PriorityItem(false, _MemberKind.UNIT_CLASS, false),
_PriorityItem(false, _MemberKind.UNIT_CLASS, true),
_PriorityItem(false, _MemberKind.UNIT_EXTENSION_TYPE, false),
_PriorityItem(false, _MemberKind.UNIT_EXTENSION_TYPE, true),
_PriorityItem(false, _MemberKind.UNIT_EXTENSION, false),
_PriorityItem(false, _MemberKind.UNIT_EXTENSION, true),
_PriorityItem(true, _MemberKind.CLASS_FIELD, false),
@ -99,6 +101,8 @@ class MemberSorter {
_sortClassMembers(unitMember.members);
} else if (unitMember is ExtensionDeclaration) {
_sortClassMembers(unitMember.members);
} else if (unitMember is ExtensionTypeDeclaration) {
_sortClassMembers(unitMember.members);
} else if (unitMember is MixinDeclaration) {
_sortClassMembers(unitMember.members);
}
@ -176,6 +180,9 @@ class MemberSorter {
} else if (member is EnumDeclaration) {
kind = _MemberKind.UNIT_CLASS;
name = member.name.lexeme;
} else if (member is ExtensionTypeDeclaration) {
kind = _MemberKind.UNIT_EXTENSION_TYPE;
name = member.name.lexeme;
} else if (member is ExtensionDeclaration) {
kind = _MemberKind.UNIT_EXTENSION;
name = member.name?.lexeme ?? '';
@ -296,6 +303,7 @@ class _MemberKind {
static const UNIT_ACCESSOR = _MemberKind('UNIT_ACCESSOR');
static const UNIT_CLASS = _MemberKind('UNIT_CLASS');
static const UNIT_EXTENSION = _MemberKind('UNIT_EXTENSION');
static const UNIT_EXTENSION_TYPE = _MemberKind('UNIT_EXTENSION_TYPE');
static const UNIT_FUNCTION = _MemberKind('UNIT_FUNCTION');
static const UNIT_FUNCTION_MAIN = _MemberKind('UNIT_FUNCTION_MAIN');
static const UNIT_FUNCTION_TYPE = _MemberKind('UNIT_FUNCTION_TYPE');

View file

@ -869,6 +869,196 @@ extension E on int {
''');
}
Future<void> test_extensionType_accessor() async {
await _parseTestUnit(r'''
extension type A(int it) {
set c(x) {}
set a(x) {}
get a => null;
get b => null;
set b(x) {}
get c => null;
}
''');
// validate change
_assertSort(r'''
extension type A(int it) {
get a => null;
set a(x) {}
get b => null;
set b(x) {}
get c => null;
set c(x) {}
}
''');
}
Future<void> test_extensionType_accessor_static() async {
await _parseTestUnit(r'''
extension type A(int it) {
get a => null;
set a(x) {}
static get b => null;
static set b(x) {}
}
''');
// validate change
_assertSort(r'''
extension type A(int it) {
static get b => null;
static set b(x) {}
get a => null;
set a(x) {}
}
''');
}
Future<void> test_extensionType_constructor() async {
await _parseTestUnit(r'''
extension type A(int it) {
A.c() { }
A.a() { }
A() {}
A.b();
}
''');
// validate change
_assertSort(r'''
extension type A(int it) {
A() {}
A.a() { }
A.b();
A.c() { }
}
''');
}
Future<void> test_extensionType_external_constructorMethod() async {
await _parseTestUnit(r'''
extension type Chart(int it) {
external Pie();
external Chart();
}
''');
// validate change
_assertSort(r'''
extension type Chart(int it) {
external Chart();
external Pie();
}
''');
}
Future<void> test_extensionType_field() async {
await _parseTestUnit(r'''
extension type A(int it) {
String c;
int a;
void toString() => null;
double b;
}
''');
// validate change
_assertSort(r'''
extension type A(int it) {
String c;
int a;
double b;
void toString() => null;
}
''');
}
Future<void> test_extensionType_field_static() async {
await _parseTestUnit(r'''
extension type A(int it) {
int b;
int a;
static int d;
static int c;
}
''');
// validate change
_assertSort(r'''
extension type A(int it) {
static int d;
static int c;
int b;
int a;
}
''');
}
Future<void> test_extensionType_method() async {
await _parseTestUnit(r'''
extension type A(int it) {
c() {}
a() {}
b() {}
}
''');
// validate change
_assertSort(r'''
extension type A(int it) {
a() {}
b() {}
c() {}
}
''');
}
Future<void> test_extensionType_method_emptyLine() async {
await _parseTestUnit(r'''
extension type A(int it) {
b() {}
a() {}
}
''');
// validate change
_assertSort(r'''
extension type A(int it) {
a() {}
b() {}
}
''');
}
Future<void> test_extensionType_method_ignoreCase() async {
await _parseTestUnit(r'''
extension type A(int it) {
m_C() {}
m_a() {}
m_B() {}
}
''');
// validate change
_assertSort(r'''
extension type A(int it) {
m_a() {}
m_B() {}
m_C() {}
}
''');
}
Future<void> test_extensionType_method_static() async {
await _parseTestUnit(r'''
extension type A(int it) {
static a() {}
b() {}
}
''');
// validate change
_assertSort(r'''
extension type A(int it) {
b() {}
static a() {}
}
''');
}
Future<void> test_mixin_accessor() async {
await _parseTestUnit(r'''
mixin M {
@ -1279,6 +1469,26 @@ extension E2 on String {}
''');
}
Future<void> test_unit_extensionTypes() async {
await _parseTestUnit(r'''
extension type E3(int it) {}
extension type E2(int it) {}
extension type _E2(int it) {}
extension type _E1(int it) {}
extension type E1(int it) {}
class Z {}
''');
// validate change
_assertSort(r'''
class Z {}
extension type E1(int it) {}
extension type E2(int it) {}
extension type E3(int it) {}
extension type _E1(int it) {}
extension type _E2(int it) {}
''');
}
Future<void> test_unit_function() async {
await _parseTestUnit(r'''
fc() {}