Skip to content

Commit 9853c92

Browse files
committed
Add support for and test super-parameters
1 parent 8894ea9 commit 9853c92

File tree

6 files changed

+429
-44
lines changed

6 files changed

+429
-44
lines changed

lib/src/model/constructor.dart

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,30 @@ class Constructor extends ModelElement
100100
}
101101
}
102102

103-
Map<String, CommentReferable>? _referenceChildren;
104103
@override
105-
Map<String, CommentReferable> get referenceChildren {
106-
if (_referenceChildren == null) {
107-
_referenceChildren = {};
108-
_referenceChildren!.addEntries(allParameters.map((param) {
109-
var paramElement = param.element;
110-
if (paramElement is FieldFormalParameterElement) {
111-
return modelBuilder.fromElement(paramElement.field!);
112-
}
113-
return param;
114-
}).generateEntries());
115-
_referenceChildren!.addEntries(typeParameters.generateEntries());
104+
late final Map<String, CommentReferable> referenceChildren = () {
105+
// Find the element that [parameter] is _really_ referring to.
106+
Element? dereferenceParameter(ParameterElement? parameter) {
107+
if (parameter is FieldFormalParameterElement) {
108+
return parameter.field;
109+
} else if (parameter is SuperFormalParameterElement) {
110+
return dereferenceParameter(parameter.superConstructorParameter);
111+
} else {
112+
return parameter;
113+
}
116114
}
117-
return _referenceChildren!;
118-
}
115+
116+
var parameterElements = allParameters.map((param) {
117+
var paramElement = dereferenceParameter(param.element);
118+
return paramElement == null
119+
? param
120+
: modelBuilder.fromElement(paramElement);
121+
});
122+
return {
123+
for (var element in parameterElements) element.referenceName: element,
124+
for (var tp in typeParameters) tp.referenceName: tp,
125+
};
126+
}();
119127

120128
@override
121129
String get referenceName =>

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ environment:
77
sdk: '>=2.14.0 <3.0.0'
88

99
dependencies:
10-
analyzer: ^2.7.0
10+
analyzer: ^3.1.0
1111
args: ^2.3.0
1212
charcode: ^1.3.1
1313
cli_util: ^0.3.5

test/end2end/model_test.dart

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2944,14 +2944,6 @@ void main() {
29442944
expect(referenceLookup(doAwesomeStuff, 'ExtendedBaseReexported.action'),
29452945
equals(MatchingLinkResult(action)));
29462946
});
2947-
2948-
test('displays default value of field formal parameter', () {
2949-
expect(
2950-
factoryConstructorThingsDefault.linkedParamsLines,
2951-
contains(
2952-
'<span class="parameter-name">fieldFormalWithDefault</span> = '
2953-
'<span class="default-value">7</span>}'));
2954-
});
29552947
});
29562948
});
29572949

0 commit comments

Comments
 (0)