Skip to content

Commit e86abf5

Browse files
authored
Fix element discovery without analyzer changes (#2050)
* Fix discovery * Add tests * Review comments
1 parent 3f6ff5a commit e86abf5

9 files changed

+220
-189
lines changed

lib/src/model.dart

+118-138
Large diffs are not rendered by default.

test/dartdoc_integration_test.dart

+5-10
Original file line numberDiff line numberDiff line change
@@ -232,26 +232,21 @@ void main() {
232232
}, timeout: Timeout.factor(2));
233233

234234
test('--footer-text excludes version', () async {
235-
String _testPackagePath =
236-
path.fromUri(_currentFileUri.resolve('../testing/test_package_options'));
235+
String _testPackagePath = path
236+
.fromUri(_currentFileUri.resolve('../testing/test_package_options'));
237237

238-
var args = <String>[
239-
dartdocPath,
240-
'--output',
241-
tempDir.path
242-
];
238+
var args = <String>[dartdocPath, '--output', tempDir.path];
243239

244240
await subprocessLauncher.runStreamed(Platform.resolvedExecutable, args,
245241
workingDirectory: _testPackagePath);
246242

247243
File outFile = File(path.join(tempDir.path, 'index.html'));
248-
RegExp footerRegex = RegExp('<footer>(.*\s*?\n?)+?</footer>', multiLine: true);
244+
RegExp footerRegex =
245+
RegExp('<footer>(.*\s*?\n?)+?</footer>', multiLine: true);
249246
// get footer, check for version number
250247
RegExpMatch m = footerRegex.firstMatch(outFile.readAsStringSync());
251248
RegExp version = RegExp(r'(\d+\.)?(\d+\.)?(\*|\d+)');
252249
expect(version.hasMatch(m.group(0)), false);
253250
});
254-
255251
}, timeout: Timeout.factor(4));
256252
}
257-

test/dartdoc_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ void main() {
258258
expect(p.name, 'test_package');
259259
expect(p.hasDocumentationFile, isTrue);
260260
// Total number of public libraries in test_package.
261-
expect(packageGraph.defaultPackage.publicLibraries, hasLength(15));
261+
expect(packageGraph.defaultPackage.publicLibraries, hasLength(16));
262262
expect(packageGraph.localPackages.length, equals(1));
263263
});
264264

@@ -327,7 +327,7 @@ void main() {
327327
PackageGraph p = results.packageGraph;
328328
expect(p.defaultPackage.name, 'test_package');
329329
expect(p.defaultPackage.hasDocumentationFile, isTrue);
330-
expect(p.localPublicLibraries, hasLength(14));
330+
expect(p.localPublicLibraries, hasLength(15));
331331
expect(p.localPublicLibraries.map((lib) => lib.name).contains('fake'),
332332
isFalse);
333333
});

test/model_test.dart

+73-36
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ void main() {
494494
expect(
495495
packageGraph
496496
.localPackages.first.defaultCategory.publicLibraries.length,
497-
equals(8));
497+
equals(9));
498498
});
499499

500500
test('Verify libraries with multiple categories show up in multiple places',
@@ -518,7 +518,7 @@ void main() {
518518
expect(
519519
packageGraph
520520
.localPackages.first.defaultCategory.publicLibraries.length,
521-
equals(8));
521+
equals(9));
522522
});
523523
});
524524

@@ -588,7 +588,7 @@ void main() {
588588
});
589589

590590
test('libraries', () {
591-
expect(packageGraph.localPublicLibraries, hasLength(13));
591+
expect(packageGraph.localPublicLibraries, hasLength(14));
592592
expect(interceptorsLib.isPublic, isFalse);
593593
});
594594

@@ -603,7 +603,7 @@ void main() {
603603

604604
Package package = packageGraph.localPackages.first;
605605
expect(package.name, 'test_package');
606-
expect(package.publicLibraries, hasLength(13));
606+
expect(package.publicLibraries, hasLength(14));
607607
});
608608

609609
test('multiple packages, sorted default', () {
@@ -696,7 +696,8 @@ void main() {
696696
// If EventTarget really does start implementing hashCode, this will
697697
// fail.
698698
expect(hashCode.href, equals('dart-core/Object/hashCode.html'));
699-
expect(hashCode.canonicalEnclosingContainer, equals(objectModelElement));
699+
expect(
700+
hashCode.canonicalEnclosingContainer, equals(objectModelElement));
700701
expect(
701702
EventTarget.publicSuperChainReversed
702703
.any((et) => et.name == 'Interceptor'),
@@ -720,13 +721,17 @@ void main() {
720721
isDeprecated,
721722
someLib,
722723
reexportOneLib,
723-
reexportTwoLib;
724-
Class SomeClass, SomeOtherClass, YetAnotherClass, AUnicornClass;
724+
reexportTwoLib,
725+
reexportThreeLib;
726+
Class SomeClass,
727+
SomeOtherClass,
728+
YetAnotherClass,
729+
AUnicornClass,
730+
ADuplicateClass;
725731

726732
setUpAll(() {
727733
dartAsyncLib = utils.testPackageGraphSdk.libraries
728734
.firstWhere((l) => l.name == 'dart:async');
729-
730735
anonLib = packageGraph.libraries
731736
.firstWhere((lib) => lib.name == 'anonymous_library');
732737

@@ -736,10 +741,13 @@ void main() {
736741
.firstWhere((lib) => lib.name == 'reexport_one');
737742
reexportTwoLib = packageGraph.libraries
738743
.firstWhere((lib) => lib.name == 'reexport_two');
744+
reexportThreeLib = packageGraph.libraries
745+
.firstWhere((lib) => lib.name == 'reexport_three');
739746
SomeClass = someLib.getClassByName('SomeClass');
740747
SomeOtherClass = someLib.getClassByName('SomeOtherClass');
741748
YetAnotherClass = someLib.getClassByName('YetAnotherClass');
742749
AUnicornClass = someLib.getClassByName('AUnicornClass');
750+
ADuplicateClass = reexportThreeLib.getClassByName('ADuplicateClass');
743751

744752
isDeprecated = packageGraph.libraries
745753
.firstWhere((lib) => lib.name == 'is_deprecated');
@@ -871,6 +879,10 @@ void main() {
871879
expect(SomeOtherClass.canonicalLibrary, reexportOneLib);
872880
expect(SomeClass.canonicalLibrary, reexportTwoLib);
873881
});
882+
883+
test('with correct show/hide behavior', () {
884+
expect(ADuplicateClass.definingLibrary.name, equals('shadowing_lib'));
885+
});
874886
});
875887

876888
group('Macros', () {
@@ -2125,40 +2137,62 @@ void main() {
21252137
.firstWhere((lib) => lib.name == 'reexport_one');
21262138
reexportTwoLib = packageGraph.libraries
21272139
.firstWhere((lib) => lib.name == 'reexport_two');
2128-
documentOnceReexportOne = reexportOneLib.extensions.firstWhere((e) => e.name == 'DocumentThisExtensionOnce');
2129-
documentOnceReexportTwo = reexportTwoLib.extensions.firstWhere((e) => e.name == 'DocumentThisExtensionOnce');
2140+
documentOnceReexportOne = reexportOneLib.extensions
2141+
.firstWhere((e) => e.name == 'DocumentThisExtensionOnce');
2142+
documentOnceReexportTwo = reexportTwoLib.extensions
2143+
.firstWhere((e) => e.name == 'DocumentThisExtensionOnce');
21302144

21312145
ext = exLibrary.extensions.firstWhere((e) => e.name == 'AppleExtension');
2132-
extensionReferencer = exLibrary.classes.firstWhere((c) => c.name == 'ExtensionReferencer');
2146+
extensionReferencer =
2147+
exLibrary.classes.firstWhere((c) => c.name == 'ExtensionReferencer');
21332148
fancyList = exLibrary.extensions.firstWhere((e) => e.name == 'FancyList');
2134-
doSomeStuff = exLibrary.classes.firstWhere((c) => c.name == 'ExtensionUser')
2135-
.allInstanceMethods.firstWhere((m) => m.name == 'doSomeStuff');
2136-
doStuff = exLibrary.extensions.firstWhere((e) => e.name == 'SimpleStringExtension')
2137-
.instanceMethods.firstWhere((m) => m.name == 'doStuff');
2149+
doSomeStuff = exLibrary.classes
2150+
.firstWhere((c) => c.name == 'ExtensionUser')
2151+
.allInstanceMethods
2152+
.firstWhere((m) => m.name == 'doSomeStuff');
2153+
doStuff = exLibrary.extensions
2154+
.firstWhere((e) => e.name == 'SimpleStringExtension')
2155+
.instanceMethods
2156+
.firstWhere((m) => m.name == 'doStuff');
21382157
extensions = exLibrary.publicExtensions.toList();
21392158
});
21402159

21412160
test('basic canonicalization for extensions', () {
21422161
expect(documentOnceReexportOne.isCanonical, isFalse);
2143-
expect(documentOnceReexportOne.href, equals(documentOnceReexportTwo.href));
2162+
expect(
2163+
documentOnceReexportOne.href, equals(documentOnceReexportTwo.href));
21442164
expect(documentOnceReexportTwo.isCanonical, isTrue);
21452165
});
21462166

21472167
// TODO(jcollins-g): implement feature and update tests
21482168
test('documentation links do not crash in base cases', () {
2149-
packageGraph.packageWarningCounter.hasWarning(doStuff, PackageWarning.notImplemented,
2169+
2170+
packageGraph.packageWarningCounter.hasWarning(
2171+
doStuff,
2172+
PackageWarning.notImplemented,
21502173
'Comment reference resolution inside extension methods is not yet implemented');
2151-
packageGraph.packageWarningCounter.hasWarning(doSomeStuff, PackageWarning.notImplemented,
2174+
packageGraph.packageWarningCounter.hasWarning(
2175+
doSomeStuff,
2176+
PackageWarning.notImplemented,
21522177
'Comment reference resolution inside extension methods is not yet implemented');
21532178
expect(doStuff.documentationAsHtml, contains('<code>another</code>'));
2154-
expect(doSomeStuff.documentationAsHtml, contains('<code>String.extensionNumber</code>'));
2179+
expect(doSomeStuff.documentationAsHtml,
2180+
contains('<code>String.extensionNumber</code>'));
21552181
});
21562182

2157-
test('references from outside an extension refer correctly to the extension', () {
2158-
expect(extensionReferencer.documentationAsHtml, contains('<code>_Shhh</code>'));
2159-
expect(extensionReferencer.documentationAsHtml, contains('<a href="ex/FancyList.html">FancyList</a>'));
2160-
expect(extensionReferencer.documentationAsHtml, contains('<a href="ex/AnExtension/call.html">AnExtension.call</a>'));
2161-
expect(extensionReferencer.documentationAsHtml, contains('<a href="reexport_two/DocumentThisExtensionOnce.html">DocumentThisExtensionOnce</a>'));
2183+
test(
2184+
'references from outside an extension refer correctly to the extension',
2185+
() {
2186+
expect(extensionReferencer.documentationAsHtml,
2187+
contains('<code>_Shhh</code>'));
2188+
expect(extensionReferencer.documentationAsHtml,
2189+
contains('<a href="ex/FancyList.html">FancyList</a>'));
2190+
expect(extensionReferencer.documentationAsHtml,
2191+
contains('<a href="ex/AnExtension/call.html">AnExtension.call</a>'));
2192+
expect(
2193+
extensionReferencer.documentationAsHtml,
2194+
contains(
2195+
'<a href="reexport_two/DocumentThisExtensionOnce.html">DocumentThisExtensionOnce</a>'));
21622196
});
21632197

21642198
test('has a fully qualified name', () {
@@ -2190,10 +2224,8 @@ void main() {
21902224
});
21912225

21922226
test('extended type has generics', () {
2193-
expect(
2194-
fancyList.extendedType.nameWithGenerics,
2195-
equals(
2196-
'List&lt;<wbr><span class="type-parameter">Z</span>&gt;'));
2227+
expect(fancyList.extendedType.nameWithGenerics,
2228+
equals('List&lt;<wbr><span class="type-parameter">Z</span>&gt;'));
21972229
});
21982230

21992231
test('get methods', () {
@@ -2231,7 +2263,8 @@ void main() {
22312263

22322264
setUpAll(() {
22332265
animal = exLibrary.enums.firstWhere((e) => e.name == 'Animal');
2234-
animalToString = animal.allInstanceMethods.firstWhere((m) => m.name == 'toString');
2266+
animalToString =
2267+
animal.allInstanceMethods.firstWhere((m) => m.name == 'toString');
22352268

22362269
/// Trigger code reference resolution
22372270
animal.documentationAsHtml;
@@ -2876,11 +2909,11 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
28762909
});
28772910

28782911
test('Fields always have line and column information', () {
2879-
expect(implicitGetterExplicitSetter.characterLocation, isNotNull);
2880-
expect(explicitGetterImplicitSetter.characterLocation, isNotNull);
2881-
expect(explicitGetterSetter.characterLocation, isNotNull);
2882-
expect(constField.characterLocation, isNotNull);
2883-
expect(aProperty.characterLocation, isNotNull);
2912+
expect(implicitGetterExplicitSetter.characterLocation, isNotNull);
2913+
expect(explicitGetterImplicitSetter.characterLocation, isNotNull);
2914+
expect(explicitGetterSetter.characterLocation, isNotNull);
2915+
expect(constField.characterLocation, isNotNull);
2916+
expect(aProperty.characterLocation, isNotNull);
28842917
});
28852918

28862919
test('covariant fields are recognized', () {
@@ -3387,7 +3420,10 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
33873420
Constructor appleConstructorFromString;
33883421
Constructor constructorTesterDefault, constructorTesterFromSomething;
33893422
Constructor syntheticConstructor;
3390-
Class apple, constCat, constructorTester, referToADefaultConstructor,
3423+
Class apple,
3424+
constCat,
3425+
constructorTester,
3426+
referToADefaultConstructor,
33913427
withSyntheticConstructor;
33923428
setUpAll(() {
33933429
apple = exLibrary.classes.firstWhere((c) => c.name == 'Apple');
@@ -3405,7 +3441,8 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
34053441
.firstWhere((c) => c.name == 'ConstructorTester.fromSomething');
34063442
referToADefaultConstructor = fakeLibrary.classes
34073443
.firstWhere((c) => c.name == 'ReferToADefaultConstructor');
3408-
withSyntheticConstructor = exLibrary.classes.firstWhere((c) => c.name == 'WithSyntheticConstructor');
3444+
withSyntheticConstructor = exLibrary.classes
3445+
.firstWhere((c) => c.name == 'WithSyntheticConstructor');
34093446
syntheticConstructor = withSyntheticConstructor.defaultConstructor;
34103447
});
34113448

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
library reexport_three;
2+
3+
// Test show/hide handling.
4+
export 'src/shadowing_lib.dart' show ADuplicateClass;
5+
// ignore: directives_ordering
6+
export 'src/shadow_lib.dart' hide ADuplicateClass;

testing/test_package/lib/reexport_two.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
/// {@category Unreal}
66
library reexport_two;
77

8-
export 'src/somelib.dart';
9-
8+
// Intentionally create some duplicates via reexporting.
109
export 'src/mixins.dart' show MixedIn, AMixin;
10+
export 'src/somelib.dart';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
library shadow_lib;
2+
3+
class ADuplicateClass {
4+
bool get aCompletelyDifferentGetter => true;
5+
}
6+
7+
class SomeOtherClass {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
library shadowing_lib;
2+
3+
class ADuplicateClass {
4+
bool get aGetter => true;
5+
}
6+
7+
class SomeMoreClassDeclaration {}

testing/test_package/lib/src/somelib.dart

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ class YetAnotherClass {}
88

99
class AUnicornClass {}
1010

11-
1211
/// A private extension.
1312
extension _Unseen on Object {
1413
void doYouSeeMe() { }

0 commit comments

Comments
 (0)