@@ -18,18 +18,16 @@ class PreferMatchFileNameVisitor extends RecursiveAstVisitor<void> {
1818 });
1919
2020 /// List of all declarations
21- Iterable <DeclarationTokenInfo > get declarations =>
22- _declarations
23- ..sort (
24- // partition into public and private
25- // put public ones first
26- // each partition sorted by declaration order
27- (a, b) =>
28- _publicDeclarationsFirst (a, b) ?? _byDeclarationOrder (a, b),
29- );
21+ Iterable <DeclarationTokenInfo > get declarations => _declarations
22+ ..sort (
23+ // partition into public and private
24+ // put public ones first
25+ // each partition sorted by declaration order
26+ (a, b) => _publicDeclarationsFirst (a, b) ?? _byDeclarationOrder (a, b),
27+ );
3028
3129 bool _shouldIgnore (Declaration node) {
32- if (excludedEntities.isEmpty) return false ;
30+ if (excludedEntities.isEmpty) return false ;
3331
3432 if (node is ClassDeclaration && excludedEntities.contains ('class' )) {
3533 return true ;
@@ -45,59 +43,61 @@ class PreferMatchFileNameVisitor extends RecursiveAstVisitor<void> {
4543 return false ;
4644 }
4745
46+ @override
47+ void visitClassDeclaration (ClassDeclaration node) {
48+ super .visitClassDeclaration (node);
4849
49- @override
50- void visitClassDeclaration (ClassDeclaration node) {
51- super .visitClassDeclaration (node);
50+ if (_shouldIgnore (node)) return ;
5251
53- if (_shouldIgnore (node)) return ;
54-
55- _declarations.add ((token: node.name, parent: node));
56- }
52+ _declarations.add ((token: node.name, parent: node));
53+ }
5754
58- @override
59- void visitExtensionDeclaration (ExtensionDeclaration node) {
60- super .visitExtensionDeclaration (node);
55+ @override
56+ void visitExtensionDeclaration (ExtensionDeclaration node) {
57+ super .visitExtensionDeclaration (node);
6158
62- if (_shouldIgnore (node)) return ;
59+ if (_shouldIgnore (node)) return ;
6360
64- final name = node.name;
65- if (name != null ) {
66- _declarations.add ((token: name, parent: node));
61+ final name = node.name;
62+ if (name != null ) {
63+ _declarations.add ((token: name, parent: node));
64+ }
6765 }
68- }
6966
70- @override
71- void visitMixinDeclaration (MixinDeclaration node) {
72- super .visitMixinDeclaration (node);
67+ @override
68+ void visitMixinDeclaration (MixinDeclaration node) {
69+ super .visitMixinDeclaration (node);
7370
74- if (_shouldIgnore (node)) return ;
71+ if (_shouldIgnore (node)) return ;
7572
76- _declarations.add ((token: node.name, parent: node));
77- }
73+ _declarations.add ((token: node.name, parent: node));
74+ }
7875
79- @override
80- void visitEnumDeclaration (EnumDeclaration node) {
81- super .visitEnumDeclaration (node);
76+ @override
77+ void visitEnumDeclaration (EnumDeclaration node) {
78+ super .visitEnumDeclaration (node);
8279
83- if (_shouldIgnore (node)) return ;
80+ if (_shouldIgnore (node)) return ;
8481
85- _declarations.add ((token: node.name, parent: node));
86- }
82+ _declarations.add ((token: node.name, parent: node));
83+ }
84+
85+ int ? _publicDeclarationsFirst (
86+ DeclarationTokenInfo a,
87+ DeclarationTokenInfo b,
88+ ) {
89+ final isAPrivate = Identifier .isPrivateName (a.token.lexeme);
90+ final isBPrivate = Identifier .isPrivateName (b.token.lexeme);
91+ if (! isAPrivate && isBPrivate) {
92+ return - 1 ;
93+ } else if (isAPrivate && ! isBPrivate) {
94+ return 1 ;
95+ }
96+ // no reorder needed;
97+ return null ;
98+ }
8799
88- int ? _publicDeclarationsFirst (DeclarationTokenInfo a,
89- DeclarationTokenInfo b,) {
90- final isAPrivate = Identifier .isPrivateName (a.token.lexeme);
91- final isBPrivate = Identifier .isPrivateName (b.token.lexeme);
92- if (! isAPrivate && isBPrivate) {
93- return - 1 ;
94- } else if (isAPrivate && ! isBPrivate) {
95- return 1 ;
100+ int _byDeclarationOrder (DeclarationTokenInfo a, DeclarationTokenInfo b) {
101+ return a.token.offset.compareTo (b.token.offset);
96102 }
97- // no reorder needed;
98- return null ;
99103}
100-
101- int _byDeclarationOrder (DeclarationTokenInfo a, DeclarationTokenInfo b) {
102- return a.token.offset.compareTo (b.token.offset);
103- }}
0 commit comments