Skip to content

Commit 9e37155

Browse files
committed
Merge pull request #694 from dart-lang/alphabetize-left-nav
Alphabetize left nav
2 parents 9f85e93 + 2cccc6f commit 9e37155

File tree

4 files changed

+133
-78
lines changed

4 files changed

+133
-78
lines changed

lib/src/model.dart

Lines changed: 71 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import 'model_utils.dart';
1616
import 'package_meta.dart';
1717
import '../markdown_processor.dart';
1818

19+
int byName(a, b) => a.name.toUpperCase().compareTo(b.name.toUpperCase());
20+
1921
final Map<Class, List<Class>> _implementors = new Map();
2022

2123
void _addToImplementors(Class c) {
@@ -536,7 +538,7 @@ class Library extends ModelElement {
536538
elements..removeWhere(isPrivate);
537539
_variables = elements
538540
.map((e) => new TopLevelVariable(e, this))
539-
.toList(growable: false);
541+
.toList(growable: false)..sort(byName);
540542

541543
return _variables;
542544
}
@@ -545,13 +547,15 @@ class Library extends ModelElement {
545547

546548
/// All variables ("properties") except constants.
547549
List<TopLevelVariable> get properties {
548-
return _getVariables().where((v) => !v.isConst).toList(growable: false);
550+
return _getVariables().where((v) => !v.isConst).toList(growable: false)
551+
..sort(byName);
549552
}
550553

551554
bool get hasConstants => _getVariables().any((v) => v.isConst);
552555

553556
List<TopLevelVariable> get constants {
554-
return _getVariables().where((v) => v.isConst).toList(growable: false);
557+
return _getVariables().where((v) => v.isConst).toList(growable: false)
558+
..sort(byName);
555559
}
556560

557561
bool get hasEnums => enums.isNotEmpty;
@@ -565,7 +569,7 @@ class Library extends ModelElement {
565569
_enums = enumClasses
566570
.where(isPublic)
567571
.map((e) => new Enum(e, this))
568-
.toList(growable: false);
572+
.toList(growable: false)..sort((a, b) => a.name.compareTo(b.name));
569573
return _enums;
570574
}
571575

@@ -587,7 +591,9 @@ class Library extends ModelElement {
587591
elements.addAll(_exportedNamespace
588592
.where((element) => element is FunctionTypeAliasElement));
589593
elements..removeWhere(isPrivate);
590-
_typeDefs = elements.map((e) => new Typedef(e, this)).toList();
594+
_typeDefs = elements
595+
.map((e) => new Typedef(e, this))
596+
.toList(growable: false)..sort(byName);
591597
return _typeDefs;
592598
}
593599

@@ -607,7 +613,7 @@ class Library extends ModelElement {
607613
elements..removeWhere(isPrivate);
608614
_functions = elements.map((e) {
609615
return new ModelFunction(e, this);
610-
}).toList(growable: false);
616+
}).toList(growable: false)..sort(byName);
611617
return _functions;
612618
}
613619

@@ -631,7 +637,7 @@ class Library extends ModelElement {
631637
_classes = types
632638
.where(isPublic)
633639
.map((e) => new Class(e, this))
634-
.toList(growable: true);
640+
.toList(growable: false)..sort(byName);
635641

636642
return _classes;
637643
}
@@ -654,7 +660,7 @@ class Library extends ModelElement {
654660

655661
List<Class> get exceptions {
656662
return _allClasses.where((c) => c.isErrorOrException).toList(
657-
growable: false);
663+
growable: false)..sort(byName);
658664
}
659665

660666
@override
@@ -669,14 +675,17 @@ class Class extends ModelElement {
669675
List<Method> _allMethods;
670676
List<Operator> _operators;
671677
List<Operator> _inheritedOperators;
678+
List<Operator> _allOperators;
672679
List<Method> _inheritedMethods;
673680
List<Method> _staticMethods;
674681
List<Method> _instanceMethods;
682+
List<Method> _allInstanceMethods;
675683
List<Field> _fields;
676684
List<Field> _staticFields;
677685
List<Field> _constants;
678686
List<Field> _instanceFields;
679687
List<Field> _inheritedProperties;
688+
List<Field> _allInstanceProperties;
680689

681690
ClassElement get _cls => (element as ClassElement);
682691

@@ -783,7 +792,7 @@ class Class extends ModelElement {
783792
_fields = _cls.fields
784793
.where(isPublic)
785794
.map((e) => new Field(e, library))
786-
.toList(growable: false);
795+
.toList(growable: false)..sort(byName);
787796

788797
return _fields;
789798
}
@@ -793,35 +802,37 @@ class Class extends ModelElement {
793802
_staticFields = _allFields
794803
.where((f) => f.isStatic)
795804
.where((f) => !f.isConst)
796-
.toList(growable: false);
805+
.toList(growable: false)..sort(byName);
797806
return _staticFields;
798807
}
799808

809+
bool get hasInstanceProperties => instanceProperties.isNotEmpty;
810+
800811
List<Field> get instanceProperties {
801812
if (_instanceFields != null) return _instanceFields;
802-
_instanceFields =
803-
_allFields.where((f) => !f.isStatic).toList(growable: false);
813+
_instanceFields = _allFields
814+
.where((f) => !f.isStatic)
815+
.toList(growable: false)..sort(byName);
804816
return _instanceFields;
805817
}
806818

807819
List<Field> get constants {
808820
if (_constants != null) return _constants;
809-
_constants = _allFields.where((f) => f.isConst).toList(growable: false);
821+
_constants = _allFields.where((f) => f.isConst).toList(growable: false)
822+
..sort((a, b) => a.name.compareTo(b.name));
810823
return _constants;
811824
}
812825

813826
bool get hasConstants => constants.isNotEmpty;
814827

815828
bool get hasStaticProperties => staticProperties.isNotEmpty;
816829

817-
bool get hasInstanceProperties => instanceProperties.isNotEmpty;
818-
819830
List<Constructor> get constructors {
820831
if (_constructors != null) return _constructors;
821832

822833
_constructors = _cls.constructors.where(isPublic).map((e) {
823834
return new Constructor(e, library);
824-
}).toList(growable: true);
835+
}).toList(growable: true)..sort(byName);
825836

826837
return _constructors;
827838
}
@@ -837,26 +848,37 @@ class Class extends ModelElement {
837848
} else {
838849
return new Operator(e, library);
839850
}
840-
}).toList(growable: false);
851+
}).toList(growable: false)..sort(byName);
841852

842853
return _allMethods;
843854
}
844855

845856
List<Operator> get operators {
846857
if (_operators != null) return _operators;
847858

848-
_operators = _methods.where((m) => m.isOperator).toList(growable: false);
859+
_operators = _methods.where((m) => m.isOperator).toList(growable: false)
860+
..sort(byName);
849861

850862
return _operators;
851863
}
852864

853865
bool get hasOperators =>
854866
operators.isNotEmpty || inheritedOperators.isNotEmpty;
855867

868+
List<Operator> get allOperators {
869+
if (_allOperators != null) return _allOperators;
870+
_allOperators = []
871+
..addAll(operators)
872+
..addAll(inheritedOperators)
873+
..sort(byName);
874+
return _allOperators;
875+
}
876+
856877
List<Method> get staticMethods {
857878
if (_staticMethods != null) return _staticMethods;
858879

859-
_staticMethods = _methods.where((m) => m.isStatic).toList(growable: false);
880+
_staticMethods = _methods.where((m) => m.isStatic).toList(growable: false)
881+
..sort(byName);
860882

861883
return _staticMethods;
862884
}
@@ -868,7 +890,7 @@ class Class extends ModelElement {
868890

869891
_instanceMethods = _methods
870892
.where((m) => !m.isStatic && !m.isOperator)
871-
.toList(growable: false);
893+
.toList(growable: false)..sort(byName);
872894

873895
return _instanceMethods;
874896
}
@@ -911,9 +933,20 @@ class Class extends ModelElement {
911933
}
912934
}
913935

936+
_inheritedMethods..sort(byName);
937+
914938
return _inheritedMethods;
915939
}
916940

941+
List<Method> get allInstanceMethods {
942+
if (_allInstanceMethods != null) return _allInstanceMethods;
943+
_allInstanceMethods = []
944+
..addAll(instanceMethods)
945+
..addAll(inheritedMethods)
946+
..sort(byName);
947+
return _allInstanceMethods;
948+
}
949+
917950
List<Method> get inheritedOperators {
918951
if (_inheritedOperators != null) return _inheritedOperators;
919952
InheritanceManager manager = new InheritanceManager(element.library);
@@ -959,6 +992,8 @@ class Class extends ModelElement {
959992
_inheritedOperators.add(new Operator.inherited(value, lib));
960993
}
961994

995+
_inheritedOperators..sort(byName);
996+
962997
return _inheritedOperators;
963998
}
964999

@@ -999,6 +1034,9 @@ class Class extends ModelElement {
9991034
_inheritedProperties.add(new Field.inherited(e, lib));
10001035
}
10011036
}
1037+
1038+
_inheritedProperties..sort(byName);
1039+
10021040
return _inheritedProperties;
10031041
}
10041042

@@ -1008,6 +1046,18 @@ class Class extends ModelElement {
10081046
bool get hasProperties =>
10091047
inheritedProperties.isNotEmpty || instanceProperties.isNotEmpty;
10101048

1049+
List<Field> get allInstanceProperties {
1050+
if (_allInstanceProperties != null) return _allInstanceProperties;
1051+
1052+
// TODO best way to make this a fixed length list?
1053+
_allInstanceProperties = []
1054+
..addAll(instanceProperties)
1055+
..addAll(inheritedProperties)
1056+
..sort(byName);
1057+
1058+
return _allInstanceProperties;
1059+
}
1060+
10111061
bool get isErrorOrException {
10121062
bool _doCheck(InterfaceType type) {
10131063
return (type.element.library.isDartCore &&
@@ -1049,7 +1099,7 @@ class Enum extends Class {
10491099
.where(isPublic)
10501100
.where((f) => f.isConst)
10511101
.map((field) => new EnumField(index++, field, library))
1052-
.toList(growable: false);
1102+
.toList(growable: false)..sort(byName);
10531103

10541104
return _constants;
10551105
}

lib/templates/_sidebar_for_class.html

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,9 @@
2222

2323
{{#class.hasInstanceProperties}}
2424
<li class="section-title"><a href="{{class.href}}#instance-properties">Properties</a></li>
25-
{{#class.instanceProperties}}
25+
{{#class.allInstanceProperties}}
2626
<li><a href="{{href}}">{{name}}</a></li>
27-
{{/class.instanceProperties}}
28-
{{#class.inheritedProperties}}
29-
<li><a href="{{href}}">{{name}}</a></li>
30-
{{/class.inheritedProperties}}
27+
{{/class.allInstanceProperties}}
3128
{{/class.hasInstanceProperties}}
3229

3330
{{#class.hasConstructors}}
@@ -39,21 +36,15 @@
3936

4037
{{#class.hasOperators}}
4138
<li class="section-title"><a href="{{class.href}}#operators">Operators</a></li>
42-
{{#class.operators}}
43-
<li><a href="{{href}}">{{name}}</a></li>
44-
{{/class.operators}}
45-
{{#class.inheritedOperators}}
39+
{{#class.allOperators}}
4640
<li><a href="{{href}}">{{name}}</a></li>
47-
{{/class.inheritedOperators}}
41+
{{/class.allOperators}}
4842
{{/class.hasOperators}}
4943

5044
{{#class.hasMethods}}
5145
<li class="section-title"><a href="{{class.href}}#methods">Methods</a></li>
52-
{{#class.instanceMethods}}
53-
<li><a href="{{href}}">{{name}}</a></li>
54-
{{/class.instanceMethods}}
55-
{{#class.inheritedMethods}}
46+
{{#class.allInstanceMethods}}
5647
<li><a href="{{href}}">{{name}}</a></li>
57-
{{/class.inheritedMethods}}
48+
{{/class.allInstanceMethods}}
5849
{{/class.hasMethods}}
5950
</ol>

lib/templates/class.html

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,9 @@ <h2>Static Methods</h2>
107107
<h2>Properties</h2>
108108

109109
<dl class="properties">
110-
{{#class.instanceProperties}}
110+
{{#class.allInstanceProperties}}
111111
{{>property}}
112-
{{/class.instanceProperties}}
113-
114-
{{#class.inheritedProperties}}
115-
{{>property}}
116-
{{/class.inheritedProperties}}
112+
{{/class.allInstanceProperties}}
117113
</dl>
118114
</section>
119115
{{/class.hasProperties}}
@@ -144,13 +140,9 @@ <h2>Constructors</h2>
144140
<section class="summary" id="operators">
145141
<h2>Operators</h2>
146142
<dl class="callables">
147-
{{#class.operators}}
148-
{{>callable}}
149-
{{/class.operators}}
150-
151-
{{#class.inheritedOperators}}
143+
{{#class.allOperators}}
152144
{{>callable}}
153-
{{/class.inheritedOperators}}
145+
{{/class.allOperators}}
154146
</dl>
155147
</section>
156148
{{/class.hasOperators}}
@@ -159,13 +151,9 @@ <h2>Operators</h2>
159151
<section class="summary" id="instance-methods">
160152
<h2>Methods</h2>
161153
<dl class="callables">
162-
{{#class.instanceMethods}}
163-
{{>callable}}
164-
{{/class.instanceMethods}}
165-
166-
{{#class.inheritedMethods}}
154+
{{#class.allInstanceMethods}}
167155
{{>callable}}
168-
{{/class.inheritedMethods}}
156+
{{/class.allInstanceMethods}}
169157
</dl>
170158
</section>
171159
{{/class.hasMethods}}

0 commit comments

Comments
 (0)