@@ -217,6 +217,9 @@ class Class extends ModelElement implements EnclosedElement {
217
217
}
218
218
219
219
/// Returns the library that encloses this element.
220
+ ///
221
+ /// If this class is exported by a library, this returns
222
+ /// the exporting library.
220
223
ModelElement get enclosingElement => library;
221
224
222
225
String get fileName => "${name }-class.html" ;
@@ -320,7 +323,7 @@ class Class extends ModelElement implements EnclosedElement {
320
323
isPublic (value) &&
321
324
! value.isOperator &&
322
325
value.enclosingElement != null ) {
323
- if (! package.isDocumented (value.enclosingElement)) {
326
+ if (! package.isInLibraryAndExported (value.enclosingElement)) {
324
327
Method m = new Method .inherited (value, this , library);
325
328
_inheritedMethods.add (m);
326
329
_genPageMethods.add (m);
@@ -375,7 +378,7 @@ class Class extends ModelElement implements EnclosedElement {
375
378
}
376
379
377
380
for (ExecutableElement value in vs.values) {
378
- if (! package.isDocumented (value.enclosingElement)) {
381
+ if (! package.isInLibraryAndExported (value.enclosingElement)) {
379
382
Operator o = new Operator .inherited (value, this , library);
380
383
_inheritedOperators.add (o);
381
384
_genPageOperators.add (o);
@@ -437,7 +440,7 @@ class Class extends ModelElement implements EnclosedElement {
437
440
if (_inheritedProperties.any ((f) => f.element == e)) {
438
441
continue ;
439
442
}
440
- if (! package.isDocumented (value.enclosingElement)) {
443
+ if (! package.isInLibraryAndExported (value.enclosingElement)) {
441
444
Field f = new Field .inherited (e, this , library);
442
445
_inheritedProperties.add (f);
443
446
_genPageProperties.add (f);
@@ -681,6 +684,8 @@ class Dynamic extends ModelElement {
681
684
///
682
685
/// Libraries are not enclosed.
683
686
abstract class EnclosedElement {
687
+ /// Returns the enclosing element, or null
688
+ /// if this is a library.
684
689
ModelElement get enclosingElement;
685
690
}
686
691
@@ -986,7 +991,13 @@ class Library extends ModelElement {
986
991
.where ((element) => element is FunctionElement ));
987
992
988
993
_functions = elements.where (isPublic).map ((e) {
989
- return new ModelFunction (e, this );
994
+ // TODO: port this logic to all names that come from exported libraries
995
+ if (e.library == this ._library ||
996
+ ! package._libraryElements.contains (e.library)) {
997
+ return new ModelFunction (e, this );
998
+ } else {
999
+ return new ModelFunction (e, new Library (e.library, this .package));
1000
+ }
990
1001
}).toList (growable: false )..sort (byName);
991
1002
992
1003
return _functions;
@@ -1061,12 +1072,19 @@ class Library extends ModelElement {
1061
1072
elements.addAll (cu.functionTypeAliases);
1062
1073
}
1063
1074
1064
- elements.addAll (_exportedNamespace.definedNames.values
1065
- .where ((element) => element is FunctionTypeAliasElement ));
1066
- elements..removeWhere (isPrivate);
1067
- _typeDefs = elements
1068
- .map ((e) => new Typedef (e, this ))
1069
- .toList (growable: false )..sort (byName);
1075
+ elements
1076
+ ..addAll (_exportedNamespace.definedNames.values
1077
+ .where ((element) => element is FunctionTypeAliasElement ))
1078
+ ..removeWhere (isPrivate);
1079
+ _typeDefs = elements.map ((e) {
1080
+ // TODO: port this logic to all names that come from exported libraries
1081
+ if (e.library == this ._library ||
1082
+ ! package._libraryElements.contains (e.library)) {
1083
+ return new Typedef (e, this );
1084
+ } else {
1085
+ return new Typedef (e, new Library (e.library, this .package));
1086
+ }
1087
+ }).toList (growable: false )..sort (byName);
1070
1088
1071
1089
return _typeDefs;
1072
1090
}
@@ -1080,18 +1098,23 @@ class Library extends ModelElement {
1080
1098
types.addAll (cu.types);
1081
1099
}
1082
1100
for (LibraryElement le in _library.exportedLibraries) {
1083
- types.addAll (le.definingCompilationUnit.types
1084
- .where ((t) => _exportedNamespace.definedNames.values.contains (t.name))
1085
- .toList ());
1101
+ types.addAll (le.definingCompilationUnit.types.where (
1102
+ (t) => _exportedNamespace.definedNames.values.contains (t.name)));
1086
1103
}
1087
1104
1105
+ // TODO: does this code duplicate the above loop through exportedLibraries?
1088
1106
types.addAll (_exportedNamespace.definedNames.values
1089
1107
.where ((element) => element is ClassElement && ! element.isEnum));
1090
1108
1091
- _classes = types
1092
- .where (isPublic)
1093
- .map ((e) => new Class (e, this ))
1094
- .toList (growable: false )..sort (byName);
1109
+ _classes = types.where (isPublic).map ((e) {
1110
+ // TODO: port this logic to all names that come from exported libraries
1111
+ if (e.library == this ._library ||
1112
+ ! package._libraryElements.contains (e.library)) {
1113
+ return new Class (e, this );
1114
+ } else {
1115
+ return new Class (e, new Library (e.library, this .package));
1116
+ }
1117
+ }).toList (growable: false )..sort (byName);
1095
1118
1096
1119
return _classes;
1097
1120
}
@@ -1105,13 +1128,15 @@ class Library extends ModelElement {
1105
1128
bool hasInExportedNamespace (Element element) {
1106
1129
Element found = _exportedNamespace.get (element.name);
1107
1130
if (found == null ) return false ;
1108
- if (found == element) return true ; // this checks more than just the name
1109
1131
1110
1132
// Fix for #587, comparison between elements isn't reliable on windows.
1111
1133
// for some reason. sigh.
1112
1134
1113
- return found.runtimeType == element.runtimeType &&
1114
- found.nameOffset == element.nameOffset;
1135
+ bool isSame = (found == element) ||
1136
+ found.runtimeType == element.runtimeType &&
1137
+ found.nameOffset == element.nameOffset;
1138
+
1139
+ return isSame;
1115
1140
}
1116
1141
1117
1142
List <TopLevelVariable > _getVariables () {
@@ -1125,10 +1150,15 @@ class Library extends ModelElement {
1125
1150
_exportedNamespace.definedNames.values.forEach ((element) {
1126
1151
if (element is PropertyAccessorElement ) elements.add (element.variable);
1127
1152
});
1128
- _variables = elements
1129
- .where (isPublic)
1130
- .map ((e) => new TopLevelVariable (e, this ))
1131
- .toList (growable: false )..sort (byName);
1153
+ _variables = elements.where (isPublic).map ((e) {
1154
+ // TODO: port this logic to all names that come from exported libraries
1155
+ if (e.library == this ._library ||
1156
+ ! package._libraryElements.contains (e.library)) {
1157
+ return new TopLevelVariable (e, this );
1158
+ } else {
1159
+ return new TopLevelVariable (e, new Library (e.library, this .package));
1160
+ }
1161
+ }).toList (growable: false )..sort (byName);
1132
1162
1133
1163
return _variables;
1134
1164
}
@@ -1539,15 +1569,17 @@ abstract class ModelElement implements Comparable, Nameable, Documentable {
1539
1569
if (name.startsWith ('_' )) {
1540
1570
return HTML_ESCAPE .convert (name);
1541
1571
}
1542
- if (! (this is Method || this is Field ) && ! package.isDocumented (element)) {
1572
+ if (! (this is Method || this is Field ) &&
1573
+ ! package.isInLibraryAndExported (element)) {
1543
1574
return HTML_ESCAPE .convert (name);
1544
1575
}
1545
1576
1577
+ // TODO: get the library that is exporting this class, not just containing it
1546
1578
ModelElement c = (this is EnclosedElement )
1547
1579
? (this as EnclosedElement ).enclosingElement
1548
1580
: null ;
1549
1581
if (c != null ) {
1550
- if (! package.isDocumented (c.element)) {
1582
+ if (! package.isInLibraryAndExported (c.element)) {
1551
1583
return HTML_ESCAPE .convert (name);
1552
1584
}
1553
1585
if (c.name.startsWith ('_' )) {
@@ -1651,12 +1683,14 @@ class Operator extends Method {
1651
1683
}
1652
1684
1653
1685
class Package implements Nameable , Documentable {
1686
+ final List <LibraryElement > _libraryElements = [];
1654
1687
final List <Library > _libraries = [];
1655
1688
final PackageMeta packageMeta;
1656
1689
final Map <String , Library > elementLibaryMap = {};
1657
1690
String _docsAsHtml;
1658
1691
1659
1692
Package (Iterable <LibraryElement > libraryElements, this .packageMeta) {
1693
+ _libraryElements.addAll (libraryElements);
1660
1694
libraryElements.forEach ((element) {
1661
1695
// add only if the element should be included in the public api
1662
1696
if (isPublic (element)) {
@@ -1740,11 +1774,14 @@ class Package implements Nameable, Documentable {
1740
1774
} else {
1741
1775
el = element;
1742
1776
}
1777
+
1743
1778
return _libraries.firstWhere ((lib) => lib.hasInExportedNamespace (el),
1744
1779
orElse: () => null );
1745
1780
}
1746
1781
1747
- bool isDocumented (Element element) => findLibraryFor (element) != null ;
1782
+ /// Returns true if element is found in a library in this package.
1783
+ bool isInLibraryAndExported (Element element) =>
1784
+ findLibraryFor (element) != null ;
1748
1785
1749
1786
String toString () => isSdk ? 'SDK' : 'Package $name ' ;
1750
1787
0 commit comments