Skip to content

Commit ba87dba

Browse files
authored
Fix function parameter references and empty href handling (#2709)
* It 'works' but no tests for new functionality yet * dartfmt * add tests for type parameters, handle more constructor parameter edge cases * dartfmt rebuild * remove debugging * This was never correct, delete hrefs for type parameters * Correct a problem with inherited docs * Remember, we need both * Correct remaining SDK issues * Remove commented out code block
1 parent f7a44cd commit ba87dba

File tree

6 files changed

+43
-28
lines changed

6 files changed

+43
-28
lines changed

lib/dartdoc.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ class Dartdoc {
377377
var links = doc.querySelectorAll('a');
378378
var stringLinks = links
379379
.map((link) => link.attributes['href'])
380-
.where((href) => href != null)
380+
.where((href) => href != null && href != '')
381381
.toList();
382382

383383
return Tuple2(stringLinks, baseHref);

lib/src/model/comment_referable.dart

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,9 @@ extension on Scope {
3737
/// [CommentReferable.referenceChildren] out of collections of other
3838
/// [CommmentReferable]s.
3939
extension CommentReferableEntryGenerators on Iterable<CommentReferable> {
40-
/// Discards all entries that do not collide with [referable],
41-
/// and generates an [MapEntry] using [referable]'s
42-
/// [CommentReferable.referenceName] as a prefix for the item that does.
43-
Iterable<MapEntry<String, CommentReferable>> onlyExplicitOnCollisionWith(
44-
CommentReferable referable) =>
45-
where((r) => r.referenceName == referable.referenceName).map(
46-
(r) => MapEntry('${referable.referenceName}.${r.referenceName}', r));
47-
48-
/// Like [onlyExplicitOnCollisionWith], except does not discard non-conflicting
49-
/// items.
40+
/// Creates ordinary references except if there is a conflict with
41+
/// [referable], it will generate a [MapEntry] using [referable]'s
42+
/// [CommentReferable.referenceName] as a prefix for the conflicting item.
5043
Iterable<MapEntry<String, CommentReferable>> explicitOnCollisionWith(
5144
CommentReferable referable) =>
5245
map((r) {

lib/src/model/getter_setter_combo.dart

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,7 @@ mixin GetterSetterCombo on ModelElement {
244244
if (_referenceChildren == null) {
245245
_referenceChildren = {};
246246
if (hasParameters) {
247-
// Parameters in combos rarely matter for anything and are not part
248-
// of the usual interface to a combo, so only reference them as part of
249-
// [Container] fallbacks or if someone wants to explicitly specify a
250-
// colliding parameter name.
251-
_referenceChildren
252-
.addEntries(parameters.onlyExplicitOnCollisionWith(this));
247+
_referenceChildren.addEntries(parameters.explicitOnCollisionWith(this));
253248
}
254249
_referenceChildren
255250
.addEntries(modelType.typeArguments.explicitOnCollisionWith(this));

lib/src/model/parameter.dart

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class Parameter extends ModelElement implements EnclosedElement {
1313
ParameterElement element, Library library, PackageGraph packageGraph,
1414
{ParameterMember originalMember})
1515
: super(element, library, packageGraph, originalMember);
16-
1716
String get defaultValue {
1817
if (!hasDefaultValue) return null;
1918
return element.defaultValueCode;
@@ -85,17 +84,16 @@ class Parameter extends ModelElement implements EnclosedElement {
8584
Map<String, CommentReferable> get referenceChildren {
8685
if (_referenceChildren == null) {
8786
_referenceChildren = {};
88-
if (isCallable) {
89-
_referenceChildren
90-
.addEntriesIfAbsent(parameters.explicitOnCollisionWith(this));
87+
var _modelType = modelType;
88+
if (_modelType is Callable) {
89+
_referenceChildren.addEntriesIfAbsent(
90+
_modelType.parameters.explicitOnCollisionWith(this));
9191
}
9292
_referenceChildren.addEntriesIfAbsent(
9393
modelType.typeArguments.explicitOnCollisionWith(this));
94-
if (modelType is Callable) {
95-
_referenceChildren.addEntriesIfAbsent((modelType as Callable)
96-
.returnType
97-
.typeArguments
98-
.explicitOnCollisionWith(this));
94+
if (_modelType is Callable) {
95+
_referenceChildren.addEntriesIfAbsent(
96+
_modelType.returnType.typeArguments.explicitOnCollisionWith(this));
9997
}
10098
}
10199
return _referenceChildren;

test/end2end/model_test.dart

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2363,7 +2363,8 @@ void main() {
23632363
function1,
23642364
topLevelFunction,
23652365
aFunctionUsingRenamedLib;
2366-
TopLevelVariable incorrectDocReference,
2366+
TopLevelVariable aSetterWithFunctionParameter,
2367+
incorrectDocReference,
23672368
incorrectDocReferenceFromEx,
23682369
nameWithTwoUnderscores,
23692370
nameWithSingleUnderscore,
@@ -2392,6 +2393,7 @@ void main() {
23922393
redHerring,
23932394
yetAnotherName,
23942395
somethingShadowyParameter;
2396+
Parameter fParam, fParamA, fParamB, fParamC;
23952397
Field forInheriting,
23962398
action,
23972399
initializeMe,
@@ -2515,9 +2517,32 @@ void main() {
25152517
.firstWhere((m) => m.name == 'aMethod');
25162518
yetAnotherName =
25172519
aMethod.allParameters.firstWhere((p) => p.name == 'yetAnotherName');
2520+
2521+
aSetterWithFunctionParameter = fakeLibrary.properties
2522+
.firstWhere((p) => p.name == 'aSetterWithFunctionParameter');
2523+
fParam = aSetterWithFunctionParameter.parameters
2524+
.firstWhere((p) => p.name == 'fParam');
2525+
fParamA = (fParam.modelType as Callable)
2526+
.parameters
2527+
.firstWhere((p) => p.name == 'fParamA');
2528+
fParamB = (fParam.modelType as Callable)
2529+
.parameters
2530+
.firstWhere((p) => p.name == 'fParamB');
2531+
fParamC = (fParam.modelType as Callable)
2532+
.parameters
2533+
.firstWhere((p) => p.name == 'fParamC');
25182534
});
25192535

25202536
group('Parameter references work properly', () {
2537+
test('via a setter with a function parameter', () {
2538+
expect(bothLookup(aSetterWithFunctionParameter, 'fParam.fParamA'),
2539+
equals(MatchingLinkResult(fParamA)));
2540+
expect(bothLookup(aSetterWithFunctionParameter, 'fParam.fParamB'),
2541+
equals(MatchingLinkResult(fParamB)));
2542+
expect(bothLookup(aSetterWithFunctionParameter, 'fParam.fParamC'),
2543+
equals(MatchingLinkResult(fParamC)));
2544+
});
2545+
25212546
test('in class scope overridden by fields', () {
25222547
expect(bothLookup(FactoryConstructorThings, 'aName'),
25232548
equals(MatchingLinkResult(aNameField)));

testing/test_package/lib/fake.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1306,4 +1306,8 @@ class TypeParameterThingsExtendedQ extends TypeParameterThings<String, FactoryCo
13061306
@override
13071307
/// I override documentation so I can reference [QTypeParam].
13081308
FactoryConstructorThings aMethod<QTypeParam>(String aParam, QTypeParam anotherParam) => null;
1309-
}
1309+
}
1310+
1311+
/// We should still be able to reference [fParam.fParamA], [fParam.fParamB],
1312+
/// and [fParam.fParamC].
1313+
void set aSetterWithFunctionParameter(bool fParam(int fParamA, String fParamB, String fParamC)) {}

0 commit comments

Comments
 (0)