@@ -16,6 +16,8 @@ import 'model_utils.dart';
16
16
import 'package_meta.dart' ;
17
17
import '../markdown_processor.dart' ;
18
18
19
+ int byName (a, b) => a.name.toUpperCase ().compareTo (b.name.toUpperCase ());
20
+
19
21
final Map <Class , List <Class >> _implementors = new Map ();
20
22
21
23
void _addToImplementors (Class c) {
@@ -536,7 +538,7 @@ class Library extends ModelElement {
536
538
elements..removeWhere (isPrivate);
537
539
_variables = elements
538
540
.map ((e) => new TopLevelVariable (e, this ))
539
- .toList (growable: false );
541
+ .toList (growable: false ).. sort (byName) ;
540
542
541
543
return _variables;
542
544
}
@@ -545,13 +547,15 @@ class Library extends ModelElement {
545
547
546
548
/// All variables ("properties") except constants.
547
549
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);
549
552
}
550
553
551
554
bool get hasConstants => _getVariables ().any ((v) => v.isConst);
552
555
553
556
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);
555
559
}
556
560
557
561
bool get hasEnums => enums.isNotEmpty;
@@ -565,7 +569,7 @@ class Library extends ModelElement {
565
569
_enums = enumClasses
566
570
.where (isPublic)
567
571
.map ((e) => new Enum (e, this ))
568
- .toList (growable: false );
572
+ .toList (growable: false ).. sort ((a, b) => a.name. compareTo (b.name)) ;
569
573
return _enums;
570
574
}
571
575
@@ -587,7 +591,9 @@ class Library extends ModelElement {
587
591
elements.addAll (_exportedNamespace
588
592
.where ((element) => element is FunctionTypeAliasElement ));
589
593
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);
591
597
return _typeDefs;
592
598
}
593
599
@@ -607,7 +613,7 @@ class Library extends ModelElement {
607
613
elements..removeWhere (isPrivate);
608
614
_functions = elements.map ((e) {
609
615
return new ModelFunction (e, this );
610
- }).toList (growable: false );
616
+ }).toList (growable: false ).. sort (byName) ;
611
617
return _functions;
612
618
}
613
619
@@ -631,7 +637,7 @@ class Library extends ModelElement {
631
637
_classes = types
632
638
.where (isPublic)
633
639
.map ((e) => new Class (e, this ))
634
- .toList (growable: true );
640
+ .toList (growable: false ).. sort (byName );
635
641
636
642
return _classes;
637
643
}
@@ -654,7 +660,7 @@ class Library extends ModelElement {
654
660
655
661
List <Class > get exceptions {
656
662
return _allClasses.where ((c) => c.isErrorOrException).toList (
657
- growable: false );
663
+ growable: false ).. sort (byName) ;
658
664
}
659
665
660
666
@override
@@ -669,14 +675,17 @@ class Class extends ModelElement {
669
675
List <Method > _allMethods;
670
676
List <Operator > _operators;
671
677
List <Operator > _inheritedOperators;
678
+ List <Operator > _allOperators;
672
679
List <Method > _inheritedMethods;
673
680
List <Method > _staticMethods;
674
681
List <Method > _instanceMethods;
682
+ List <Method > _allInstanceMethods;
675
683
List <Field > _fields;
676
684
List <Field > _staticFields;
677
685
List <Field > _constants;
678
686
List <Field > _instanceFields;
679
687
List <Field > _inheritedProperties;
688
+ List <Field > _allInstanceProperties;
680
689
681
690
ClassElement get _cls => (element as ClassElement );
682
691
@@ -783,7 +792,7 @@ class Class extends ModelElement {
783
792
_fields = _cls.fields
784
793
.where (isPublic)
785
794
.map ((e) => new Field (e, library))
786
- .toList (growable: false );
795
+ .toList (growable: false ).. sort (byName) ;
787
796
788
797
return _fields;
789
798
}
@@ -793,35 +802,37 @@ class Class extends ModelElement {
793
802
_staticFields = _allFields
794
803
.where ((f) => f.isStatic)
795
804
.where ((f) => ! f.isConst)
796
- .toList (growable: false );
805
+ .toList (growable: false ).. sort (byName) ;
797
806
return _staticFields;
798
807
}
799
808
809
+ bool get hasInstanceProperties => instanceProperties.isNotEmpty;
810
+
800
811
List <Field > get instanceProperties {
801
812
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);
804
816
return _instanceFields;
805
817
}
806
818
807
819
List <Field > get constants {
808
820
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));
810
823
return _constants;
811
824
}
812
825
813
826
bool get hasConstants => constants.isNotEmpty;
814
827
815
828
bool get hasStaticProperties => staticProperties.isNotEmpty;
816
829
817
- bool get hasInstanceProperties => instanceProperties.isNotEmpty;
818
-
819
830
List <Constructor > get constructors {
820
831
if (_constructors != null ) return _constructors;
821
832
822
833
_constructors = _cls.constructors.where (isPublic).map ((e) {
823
834
return new Constructor (e, library);
824
- }).toList (growable: true );
835
+ }).toList (growable: true ).. sort (byName) ;
825
836
826
837
return _constructors;
827
838
}
@@ -837,26 +848,37 @@ class Class extends ModelElement {
837
848
} else {
838
849
return new Operator (e, library);
839
850
}
840
- }).toList (growable: false );
851
+ }).toList (growable: false ).. sort (byName) ;
841
852
842
853
return _allMethods;
843
854
}
844
855
845
856
List <Operator > get operators {
846
857
if (_operators != null ) return _operators;
847
858
848
- _operators = _methods.where ((m) => m.isOperator).toList (growable: false );
859
+ _operators = _methods.where ((m) => m.isOperator).toList (growable: false )
860
+ ..sort (byName);
849
861
850
862
return _operators;
851
863
}
852
864
853
865
bool get hasOperators =>
854
866
operators.isNotEmpty || inheritedOperators.isNotEmpty;
855
867
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
+
856
877
List <Method > get staticMethods {
857
878
if (_staticMethods != null ) return _staticMethods;
858
879
859
- _staticMethods = _methods.where ((m) => m.isStatic).toList (growable: false );
880
+ _staticMethods = _methods.where ((m) => m.isStatic).toList (growable: false )
881
+ ..sort (byName);
860
882
861
883
return _staticMethods;
862
884
}
@@ -868,7 +890,7 @@ class Class extends ModelElement {
868
890
869
891
_instanceMethods = _methods
870
892
.where ((m) => ! m.isStatic && ! m.isOperator)
871
- .toList (growable: false );
893
+ .toList (growable: false ).. sort (byName) ;
872
894
873
895
return _instanceMethods;
874
896
}
@@ -911,9 +933,20 @@ class Class extends ModelElement {
911
933
}
912
934
}
913
935
936
+ _inheritedMethods..sort (byName);
937
+
914
938
return _inheritedMethods;
915
939
}
916
940
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
+
917
950
List <Method > get inheritedOperators {
918
951
if (_inheritedOperators != null ) return _inheritedOperators;
919
952
InheritanceManager manager = new InheritanceManager (element.library);
@@ -959,6 +992,8 @@ class Class extends ModelElement {
959
992
_inheritedOperators.add (new Operator .inherited (value, lib));
960
993
}
961
994
995
+ _inheritedOperators..sort (byName);
996
+
962
997
return _inheritedOperators;
963
998
}
964
999
@@ -999,6 +1034,9 @@ class Class extends ModelElement {
999
1034
_inheritedProperties.add (new Field .inherited (e, lib));
1000
1035
}
1001
1036
}
1037
+
1038
+ _inheritedProperties..sort (byName);
1039
+
1002
1040
return _inheritedProperties;
1003
1041
}
1004
1042
@@ -1008,6 +1046,18 @@ class Class extends ModelElement {
1008
1046
bool get hasProperties =>
1009
1047
inheritedProperties.isNotEmpty || instanceProperties.isNotEmpty;
1010
1048
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
+
1011
1061
bool get isErrorOrException {
1012
1062
bool _doCheck (InterfaceType type) {
1013
1063
return (type.element.library.isDartCore &&
@@ -1049,7 +1099,7 @@ class Enum extends Class {
1049
1099
.where (isPublic)
1050
1100
.where ((f) => f.isConst)
1051
1101
.map ((field) => new EnumField (index++ , field, library))
1052
- .toList (growable: false );
1102
+ .toList (growable: false ).. sort (byName) ;
1053
1103
1054
1104
return _constants;
1055
1105
}
0 commit comments