Skip to content

Commit 13edc30

Browse files
committed
WIP
1 parent c4b8764 commit 13edc30

File tree

73 files changed

+2913
-47
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+2913
-47
lines changed

lib/src/model.dart

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -963,10 +963,15 @@ class Library extends ModelElement {
963963
List<ClassElement> enumClasses = [];
964964
enumClasses.addAll(_exportedNamespace.definedNames.values
965965
.where((element) => element is ClassElement && element.isEnum));
966-
_enums = enumClasses
967-
.where(isPublic)
968-
.map((e) => new Enum(e, this))
969-
.toList(growable: false)..sort(byName);
966+
_enums = enumClasses.where(isPublic).map((e) {
967+
if (e.library != this._library &&
968+
_exportedNamespace.definedNames.values.contains(e) &&
969+
package._libraryElements.contains(e.library)) {
970+
return new Enum(e, new Library(e.library, this.package));
971+
} else {
972+
return new Enum(e, this.library);
973+
}
974+
}).toList(growable: false)..sort(byName);
970975

971976
return _enums;
972977
}
@@ -991,12 +996,12 @@ class Library extends ModelElement {
991996
.where((element) => element is FunctionElement));
992997

993998
_functions = elements.where(isPublic).map((e) {
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+
if (e.library != this._library &&
1000+
_exportedNamespace.definedNames.values.contains(e) &&
1001+
package._libraryElements.contains(e.library)) {
9991002
return new ModelFunction(e, new Library(e.library, this.package));
1003+
} else {
1004+
return new ModelFunction(e, this.library);
10001005
}
10011006
}).toList(growable: false)..sort(byName);
10021007

@@ -1077,12 +1082,12 @@ class Library extends ModelElement {
10771082
.where((element) => element is FunctionTypeAliasElement))
10781083
..removeWhere(isPrivate);
10791084
_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+
if (e.library != this._library &&
1086+
_exportedNamespace.definedNames.values.contains(e) &&
1087+
package._libraryElements.contains(e.library)) {
10851088
return new Typedef(e, new Library(e.library, this.package));
1089+
} else {
1090+
return new Typedef(e, this.library);
10861091
}
10871092
}).toList(growable: false)..sort(byName);
10881093

@@ -1107,12 +1112,12 @@ class Library extends ModelElement {
11071112
.where((element) => element is ClassElement && !element.isEnum));
11081113

11091114
_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+
if (e.library != this._library &&
1116+
_exportedNamespace.definedNames.values.contains(e) &&
1117+
package._libraryElements.contains(e.library)) {
11151118
return new Class(e, new Library(e.library, this.package));
1119+
} else {
1120+
return new Class(e, this.library);
11161121
}
11171122
}).toList(growable: false)..sort(byName);
11181123

@@ -1151,7 +1156,6 @@ class Library extends ModelElement {
11511156
if (element is PropertyAccessorElement) elements.add(element.variable);
11521157
});
11531158
_variables = elements.where(isPublic).map((e) {
1154-
// TODO: port this logic to all names that come from exported libraries
11551159
if (e.library == this._library ||
11561160
!package._libraryElements.contains(e.library)) {
11571161
return new TopLevelVariable(e, this);

test/dartdoc_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void main() {
3939
Package p = results.package;
4040
expect(p.name, 'test_package');
4141
expect(p.hasDocumentationFile, isTrue);
42-
expect(p.libraries, hasLength(9));
42+
expect(p.libraries, hasLength(10));
4343
});
4444

4545
test('generate docs for ${path.basename(testPackageBadDir.path)} fails',
@@ -96,7 +96,7 @@ void main() {
9696
Package p = results.package;
9797
expect(p.name, 'test_package');
9898
expect(p.hasDocumentationFile, isTrue);
99-
expect(p.libraries, hasLength(8));
99+
expect(p.libraries, hasLength(9));
100100
expect(p.libraries.map((lib) => lib.name).contains('fake'), isFalse);
101101
});
102102
});

test/model_test.dart

Lines changed: 75 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ void main() {
4545
expect(package.name, 'test_package');
4646
});
4747

48-
test('libraries', () {
49-
expect(package.libraries, hasLength(7));
48+
test('has all the libraries', () {
49+
expect(package.libraries, hasLength(8));
5050
});
5151

5252
test('is documented in library', () {
@@ -482,11 +482,12 @@ void main() {
482482
List<Class> classes;
483483
Class Apple, B, Cat, Cool, Dog, F, Dep, SpecialList;
484484
Class ExtendingClass, CatString;
485-
Class Helper, CoolFromExporter;
485+
Class Helper, CoolFromExporter, ExportedClass;
486486

487487
setUp(() {
488488
classes = exLibrary.classes;
489489
CoolFromExporter = classes.firstWhere((c) => c.name == 'Cool');
490+
ExportedClass = classes.firstWhere((c) => c.name == 'ExportedClass');
490491
Helper = classes.firstWhere((c) => c.name == 'Helper');
491492
Apple = classes.firstWhere((c) => c.name == 'Apple');
492493
B = classes.firstWhere((c) => c.name == 'B');
@@ -529,7 +530,7 @@ void main() {
529530
});
530531

531532
test('correctly finds all the classes', () {
532-
expect(classes, hasLength(18));
533+
expect(classes, hasLength(19));
533534
});
534535

535536
test('abstract', () {
@@ -619,20 +620,27 @@ void main() {
619620
});
620621

621622
test(
622-
'exported class from a src library should have linkedName with a link to the exporting class library',
623-
() {
623+
'exported class from a src library should have linkedName with a '
624+
'link to the exporting class library', () {
624625
expect(Helper.linkedName, startsWith('<a href="ex'));
625626
});
626627

627628
test(
628-
'exported class from a public library should have linkedName with a link to origin library',
629-
() {
629+
'exported class from a public library should have linkedName '
630+
'with a link to origin library', () {
630631
expect(Cool.linkedName, startsWith('<a href="fake/'));
631632
});
632633

633634
test(
634-
'exported class from a public library two levels deep should have linkedName with a link to origin library',
635-
() {
635+
'exported class, without a show, from a public library '
636+
'should have linkedName with a link to origin library', () {
637+
expect(ExportedClass.linkedName,
638+
startsWith('<a href="to_be_exported/ExportedClass'));
639+
});
640+
641+
test(
642+
'exported class from a public library two levels deep should have '
643+
'linkedName with a link to origin library', () {
636644
expect(CoolFromExporter.linkedName, startsWith('<a href="fake/Cool'));
637645
});
638646

@@ -718,10 +726,33 @@ void main() {
718726
});
719727

720728
group('Enum', () {
721-
Enum animal;
729+
Enum animal, Color, ExportedEnum;
722730

723731
setUp(() {
724732
animal = exLibrary.enums.firstWhere((e) => e.name == 'Animal');
733+
Color = exLibrary.enums.firstWhere((e) => e.name == 'Color');
734+
ExportedEnum =
735+
exLibrary.enums.firstWhere((e) => e.name == 'ExportedEnum');
736+
});
737+
738+
test(
739+
'exported enum with a show from a public library should have '
740+
'linkedName with a link to origin library', () {
741+
expect(Color.linkedName, startsWith('<a href="fake/Color'));
742+
});
743+
744+
test(
745+
'exported enum without a show from a public library should '
746+
'have linkedName '
747+
'with a link to origin library', () {
748+
expect(ExportedEnum.linkedName,
749+
startsWith('<a href="to_be_exported/ExportedEnum'));
750+
});
751+
752+
test(
753+
'should have linkedName '
754+
'with a link to this library', () {
755+
expect(animal.linkedName, startsWith('<a href="ex/Animal'));
725756
});
726757

727758
test('has a fully qualified name', () {
@@ -765,10 +796,12 @@ void main() {
765796
ModelFunction f1;
766797
ModelFunction thisIsAsync;
767798
ModelFunction topLevelFunction;
768-
ModelFunction short, helperFunction;
799+
ModelFunction short, helperFunction, exportedFunction;
769800

770801
setUp(() {
771802
short = exLibrary.functions.firstWhere((f) => f.name == 'short');
803+
exportedFunction =
804+
exLibrary.functions.firstWhere((f) => f.name == 'exportedFunction');
772805
helperFunction =
773806
exLibrary.functions.firstWhere((f) => f.name == 'helperFunction');
774807
f1 = exLibrary.functions.firstWhere((f) => f.name == 'function1');
@@ -779,9 +812,16 @@ void main() {
779812
});
780813

781814
test(
782-
'exported function from a public library should have linkedName with a link to origin library',
783-
() {
784-
expect(short.linkedName, startsWith('<a href="fake/'));
815+
'exported function with a show from a public library should have '
816+
'linkedName with a link to origin library', () {
817+
expect(short.linkedName, startsWith('<a href="fake/short'));
818+
});
819+
820+
test(
821+
'exported function without a show from a public library should have '
822+
'linkedName with a link to origin library', () {
823+
expect(exportedFunction.linkedName,
824+
startsWith('<a href="to_be_exported/exportedFunction'));
785825
});
786826

787827
test(
@@ -1172,7 +1212,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
11721212
group('Top-level Variable', () {
11731213
TopLevelVariable v;
11741214
TopLevelVariable v3, justGetter, justSetter;
1175-
TopLevelVariable setAndGet, mapWithDynamicKeys, topLevelVar;
1215+
TopLevelVariable setAndGet, mapWithDynamicKeys, topLevelVar, exportedField;
11761216

11771217
setUp(() {
11781218
v = exLibrary.properties.firstWhere((p) => p.name == 'number');
@@ -1187,6 +1227,8 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
11871227
.firstWhere((p) => p.name == 'mapWithDynamicKeys');
11881228
topLevelVar =
11891229
exLibrary.properties.firstWhere((p) => p.name == 'topLevelVar');
1230+
exportedField =
1231+
exLibrary.properties.firstWhere((p) => p.name == 'exportedField');
11901232
});
11911233

11921234
test('has a fully qualified name', () {
@@ -1201,11 +1243,16 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
12011243
equals('String'));
12021244
});
12031245

1204-
test('linkedName for exported variable has origin library', () {
1246+
test('linkedName for exported variable via show has origin library', () {
12051247
expect(mapWithDynamicKeys.linkedName,
12061248
contains('href="fake/mapWithDynamicKeys.html"'));
12071249
});
12081250

1251+
test('linkedName for exported variable via show has origin library', () {
1252+
expect(exportedField.linkedName,
1253+
contains('href="to_be_exported/exportedField.html"'));
1254+
});
1255+
12091256
test(
12101257
'linkedName for exported variable from private library has exported library',
12111258
() {
@@ -1216,8 +1263,8 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
12161263
expect(v.enclosingElement.name, equals(exLibrary.name));
12171264
});
12181265

1219-
test('found six properties', () {
1220-
expect(exLibrary.properties, hasLength(7));
1266+
test('found eight properties', () {
1267+
expect(exLibrary.properties, hasLength(8));
12211268
});
12221269

12231270
test('linked return type is a double', () {
@@ -1359,13 +1406,15 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
13591406
});
13601407

13611408
group('Typedef', () {
1362-
Typedef t, FakeProcesses, DoThing;
1409+
Typedef t, FakeProcesses, DoThing, ExportedTypeDef;
13631410

13641411
setUp(() {
13651412
t = exLibrary.typedefs.firstWhere((t) => t.name == 'processMessage');
13661413
FakeProcesses =
13671414
exLibrary.typedefs.firstWhere((t) => t.name == 'FakeProcesses');
13681415
DoThing = exLibrary.typedefs.firstWhere((t) => t.name == 'DoThing');
1416+
ExportedTypeDef =
1417+
exLibrary.typedefs.firstWhere((t) => t.name == 'ExportedTypeDef');
13691418
});
13701419

13711420
test('has a fully qualified name', () {
@@ -1384,11 +1433,16 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
13841433
expect(t.linkedReturnType, equals('String'));
13851434
});
13861435

1387-
test('linkedName for exported typedef is origin library', () {
1436+
test('linkedName for exported via show typedef is origin library', () {
13881437
expect(
13891438
FakeProcesses.linkedName, contains('href="fake/FakeProcesses.html"'));
13901439
});
13911440

1441+
test('linkedName for exported without show typedef is origin library', () {
1442+
expect(ExportedTypeDef.linkedName,
1443+
contains('href="to_be_exported/ExportedTypeDef.html"'));
1444+
});
1445+
13921446
test('linkedName for private exported typedef is exporting library', () {
13931447
expect(DoThing.linkedName, contains('href="ex/DoThing.html"'));
13941448
});

test/src/utils.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ void init() {
4141
'lib/anonymous_library.dart',
4242
'lib/another_anonymous_lib.dart',
4343
'lib/is_deprecated.dart',
44-
'lib/exporter.dart'
44+
'lib/exporter.dart',
45+
'lib/to_be_exported.dart'
4546
];
4647

4748
testPackage = _bootPackage(pathsForTestLib, 'test_package');

test_package/lib/example.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ import 'src/mylib.dart' show Helper;
77

88
export 'dart:core' show deprecated, Deprecated;
99

10-
// export a class, a field, and a typedef
11-
export 'fake.dart' show Cool, mapWithDynamicKeys, FakeProcesses, short;
10+
// export everything without a show
11+
export 'to_be_exported.dart';
12+
13+
// export a class, a field, a typedef, enum, and a function via show
14+
export 'fake.dart' show Cool, mapWithDynamicKeys, FakeProcesses, short, Color;
1215
export 'src/mylib.dart' show Helper, topLevelVar, DoThing, helperFunction;
1316

1417
const String COLOR = 'red';

test_package/lib/to_be_exported.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
library to_be_exported;
2+
3+
String exportedField;
4+
5+
void exportedFunction() {}
6+
7+
typedef void ExportedTypeDef();
8+
9+
class ExportedClass {}
10+
11+
enum ExportedEnum { ONE, TWO, THREE }

test_package_docs/anonymous_library/anonymous_library-library.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ <h5><a href="index.html">test_package</a></h5>
7878
<li><a href="ex/ex-library.html">ex</a></li>
7979
<li><a href="exporter/exporter-library.html">exporter</a></li>
8080
<li><a class="deprecated" href="is_deprecated/is_deprecated-library.html">is_deprecated</a></li>
81+
<li><a href="to_be_exported/to_be_exported-library.html">to_be_exported</a></li>
8182
<li><a href="two_exports/two_exports-library.html">two_exports</a></li>
8283
</ol>
8384
</div>

test_package_docs/another_anonymous_lib/another_anonymous_lib-library.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ <h5><a href="index.html">test_package</a></h5>
7878
<li><a href="ex/ex-library.html">ex</a></li>
7979
<li><a href="exporter/exporter-library.html">exporter</a></li>
8080
<li><a class="deprecated" href="is_deprecated/is_deprecated-library.html">is_deprecated</a></li>
81+
<li><a href="to_be_exported/to_be_exported-library.html">to_be_exported</a></li>
8182
<li><a href="two_exports/two_exports-library.html">two_exports</a></li>
8283
</ol>
8384
</div>

test_package_docs/code_in_comments/code_in_comments-library.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ <h5><a href="index.html">test_package</a></h5>
7575
<li><a href="ex/ex-library.html">ex</a></li>
7676
<li><a href="exporter/exporter-library.html">exporter</a></li>
7777
<li><a class="deprecated" href="is_deprecated/is_deprecated-library.html">is_deprecated</a></li>
78+
<li><a href="to_be_exported/to_be_exported-library.html">to_be_exported</a></li>
7879
<li><a href="two_exports/two_exports-library.html">two_exports</a></li>
7980
</ol>
8081
</div>

test_package_docs/css/css-library.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ <h5><a href="index.html">test_package</a></h5>
7878
<li><a href="ex/ex-library.html">ex</a></li>
7979
<li><a href="exporter/exporter-library.html">exporter</a></li>
8080
<li><a class="deprecated" href="is_deprecated/is_deprecated-library.html">is_deprecated</a></li>
81+
<li><a href="to_be_exported/to_be_exported-library.html">to_be_exported</a></li>
8182
<li><a href="two_exports/two_exports-library.html">two_exports</a></li>
8283
</ol>
8384
</div>

0 commit comments

Comments
 (0)