Skip to content

Commit 1b8273a

Browse files
authored
Fix links to overriden methods in docs for base class (#1998)
* Fix links to overriden methods in docs for base class * fix spelling, format test code
1 parent bce994d commit 1b8273a

File tree

6 files changed

+57
-7
lines changed

6 files changed

+57
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 0.28.5-dev
22
* Support the latest version of `package:analyzer`.
3+
* Fix hyperlinks to overriden methods (#1994).
34

45
## 0.28.4
56
* **Breaking change** Change the default for `allow-tools` command line flag to false.

lib/src/markdown_processor.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,10 @@ class _MarkdownCommentReference {
647647

648648
for (Class tryClass in tryClasses) {
649649
if (tryClass != null) {
650+
if (codeRefChomped.contains('.') &&
651+
!codeRefChomped.startsWith(tryClass.name)) {
652+
continue;
653+
}
650654
_getResultsForClass(tryClass);
651655
}
652656
results.remove(null);

test/dartdoc_test.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ void main() {
100100
});
101101

102102
test('errors generate errors even when warnings are off', () async {
103-
Dartdoc dartdoc = await buildDartdoc(['--allow-tools'], testPackageToolError, tempDir);
103+
Dartdoc dartdoc =
104+
await buildDartdoc(['--allow-tools'], testPackageToolError, tempDir);
104105
DartdocResults results = await dartdoc.generateDocsBase();
105106
PackageGraph p = results.packageGraph;
106107
Iterable<String> unresolvedToolErrors = p
@@ -258,7 +259,7 @@ void main() {
258259
expect(p.name, 'test_package');
259260
expect(p.hasDocumentationFile, isTrue);
260261
// Total number of public libraries in test_package.
261-
expect(packageGraph.defaultPackage.publicLibraries, hasLength(12));
262+
expect(packageGraph.defaultPackage.publicLibraries, hasLength(14));
262263
expect(packageGraph.localPackages.length, equals(1));
263264
});
264265

@@ -327,7 +328,7 @@ void main() {
327328
PackageGraph p = results.packageGraph;
328329
expect(p.defaultPackage.name, 'test_package');
329330
expect(p.defaultPackage.hasDocumentationFile, isTrue);
330-
expect(p.localPublicLibraries, hasLength(11));
331+
expect(p.localPublicLibraries, hasLength(13));
331332
expect(p.localPublicLibraries.map((lib) => lib.name).contains('fake'),
332333
isFalse);
333334
});

test/model_test.dart

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ void main() {
6161
Library errorLibrary;
6262
Library twoExportsLib;
6363
Library interceptorsLib;
64+
Library baseClassLib;
6465
PackageGraph sdkAsPackageGraph;
6566
Library dartAsync;
6667

@@ -82,6 +83,8 @@ void main() {
8283
packageGraph.libraries.firstWhere((lib) => lib.name == 'two_exports');
8384
interceptorsLib = packageGraph.libraries
8485
.firstWhere((lib) => lib.name == 'dart:_interceptors');
86+
baseClassLib =
87+
packageGraph.libraries.firstWhere((lib) => lib.name == 'base_class');
8588
sdkAsPackageGraph = utils.testPackageGraphSdk;
8689
});
8790

@@ -492,7 +495,7 @@ void main() {
492495
expect(
493496
packageGraph
494497
.localPackages.first.defaultCategory.publicLibraries.length,
495-
equals(5));
498+
equals(7));
496499
});
497500

498501
test('Verify libraries with multiple categories show up in multiple places',
@@ -516,7 +519,7 @@ void main() {
516519
expect(
517520
packageGraph
518521
.localPackages.first.defaultCategory.publicLibraries.length,
519-
equals(5));
522+
equals(7));
520523
});
521524
});
522525

@@ -588,7 +591,7 @@ void main() {
588591
});
589592

590593
test('libraries', () {
591-
expect(packageGraph.localPublicLibraries, hasLength(10));
594+
expect(packageGraph.localPublicLibraries, hasLength(12));
592595
expect(interceptorsLib.isPublic, isFalse);
593596
});
594597

@@ -603,7 +606,7 @@ void main() {
603606

604607
Package package = packageGraph.localPackages.first;
605608
expect(package.name, 'test_package');
606-
expect(package.publicLibraries, hasLength(10));
609+
expect(package.publicLibraries, hasLength(12));
607610
});
608611

609612
test('multiple packages, sorted default', () {
@@ -1432,6 +1435,15 @@ void main() {
14321435
contains('<a href="ex/B-class.html">ex.B</a>'));
14331436
});
14341437

1438+
test('link to override method in implementer from base class', () {
1439+
final Class helperClass =
1440+
baseClassLib.classes.firstWhere((c) => c.name == 'Constraints');
1441+
expect(
1442+
helperClass.documentationAsHtml,
1443+
contains(
1444+
'<a href="override_class/BoxConstraints/debugAssertIsValid.html">BoxConstraints.debugAssertIsValid</a>'));
1445+
});
1446+
14351447
test(
14361448
'link to a name of a class from an imported library that exports the name',
14371449
() {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
library base_class;
2+
3+
/// Abstract class Constraints
4+
/// * The [debugAssertIsValid] method, which should assert if there's anything
5+
/// wrong with the constraints object. (We use this approach rather than
6+
/// asserting in constructors so that our constructors can be `const` and so
7+
/// that it is possible to create invalid constraints temporarily while
8+
/// building valid ones.) See the implementation of
9+
/// [BoxConstraints.debugAssertIsValid] for an example of the detailed checks
10+
/// that can be made.
11+
abstract class Constraints {
12+
/// Abstract const constructor. This constructor enables subclasses to provide
13+
/// const constructors so that they can be used in const expressions.
14+
const Constraints();
15+
16+
/// Method is overriden in implementations.
17+
bool debugAssertIsValid() {
18+
return true;
19+
}
20+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import 'base_class.dart';
2+
3+
class BoxConstraints extends Constraints {
4+
/// Creates box constraints with the given constraints.
5+
const BoxConstraints();
6+
7+
/// Overrides the method in the superclass.
8+
@override
9+
bool debugAssertIsValid() {
10+
return false;
11+
}
12+
}

0 commit comments

Comments
 (0)