Skip to content

Commit d0db2f9

Browse files
astashovdevoncarew
authored andcommitted
Fix double props when inherited from parameterized class [#1228] (#1303)
Sometimes, when a subclass inherits properties from a parameterized class, they appear twice in the docs. That happens, because (by some reason, I'm not sure why) the field objects for those getters and setters have different references (though they are the same - their names are the same, returning types are the same, etc). Since `FieldElementImpl` doesn't override default equality, after we added the field for getter into `_inheritedProperties`, when handling setter, we compare fields of getter and setter by reference there: https://github.com/dart-lang/dartdoc/blob/38a7863ed87892461d6ac4c448a6a719fbe95463/lib/src/model.dart#L479 And usually these are the same object, so we won't see 2 properties in the generated docs. But in that case by some reason they are 2 different objects, so we add the field of the setter as well, and then we have 2 same props in the generated docs as a result. It seems like we can safely compare their names (since there couldn't be 2 properties with the same name in a class anyway). That would fix the problem. I've added that in this commit, and also a unit test covering that case. Fixes #1228
1 parent 266b5b1 commit d0db2f9

Some content is hidden

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

60 files changed

+2711
-3
lines changed

lib/src/model.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ class Class extends ModelElement implements EnclosedElement {
476476
value.enclosingElement != null) {
477477
// TODO: why is this here?
478478
var e = value.variable;
479-
if (_inheritedProperties.any((f) => f.element == e)) {
479+
if (_inheritedProperties.any((f) => f.element.name == e.name)) {
480480
continue;
481481
}
482482
if (!package.isDocumented(value.enclosingElement)) {

test/model_test.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ void main() {
528528
});
529529

530530
test('correctly finds all the classes', () {
531-
expect(classes, hasLength(18));
531+
expect(classes, hasLength(20));
532532
});
533533

534534
test('abstract', () {
@@ -1188,6 +1188,11 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
11881188
test('a stand-alone setter does not have a getter', () {
11891189
expect(onlySetter.getter, isNull);
11901190
});
1191+
1192+
test('has one inherited property for getter/setter when inherited from parameterized class', () {
1193+
Class withGenericSub = exLibrary.classes.firstWhere((c) => c.name == 'WithGenericSub');
1194+
expect(withGenericSub.inheritedProperties.where((p) => p.name == "prop").length, equals(1));
1195+
});
11911196
});
11921197

11931198
group('Accessor', () {

testing/test_package/lib/example.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ class Apple {
130130
void printMsg(String msg, [bool linebreak]) {}
131131
}
132132

133+
class WithGeneric<T> {
134+
T prop;
135+
WithGeneric(this.prop);
136+
}
137+
138+
class WithGenericSub extends WithGeneric<Apple> {
139+
WithGenericSub(Apple prop) : super(prop);
140+
}
141+
133142
/// Extends class [Apple], use [new Apple] or [new Apple.fromString]
134143
///
135144
/// <pre>

testing/test_package_docs/ex/Animal-class.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ <h5><a href="ex/ex-library.html">ex</a></h5>
121121
<li><a href="ex/PublicClassImplementsPrivateInterface-class.html">PublicClassImplementsPrivateInterface</a></li>
122122
<li><a href="ex/ShapeType-class.html">ShapeType</a></li>
123123
<li><a href="ex/SpecializedDuration-class.html">SpecializedDuration</a></li>
124+
<li><a href="ex/WithGeneric-class.html">WithGeneric</a></li>
125+
<li><a href="ex/WithGenericSub-class.html">WithGenericSub</a></li>
124126

125127
<li class="section-title"><a href="ex/ex-library.html#exceptions">Exceptions</a></li>
126128
<li><a href="ex/MyError-class.html">MyError</a></li>

testing/test_package_docs/ex/Apple-class.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ <h5><a href="ex/ex-library.html">ex</a></h5>
125125
<li><a href="ex/PublicClassImplementsPrivateInterface-class.html">PublicClassImplementsPrivateInterface</a></li>
126126
<li><a href="ex/ShapeType-class.html">ShapeType</a></li>
127127
<li><a href="ex/SpecializedDuration-class.html">SpecializedDuration</a></li>
128+
<li><a href="ex/WithGeneric-class.html">WithGeneric</a></li>
129+
<li><a href="ex/WithGenericSub-class.html">WithGenericSub</a></li>
128130

129131
<li class="section-title"><a href="ex/ex-library.html#exceptions">Exceptions</a></li>
130132
<li><a href="ex/MyError-class.html">MyError</a></li>

testing/test_package_docs/ex/B-class.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ <h5><a href="ex/ex-library.html">ex</a></h5>
123123
<li><a href="ex/PublicClassImplementsPrivateInterface-class.html">PublicClassImplementsPrivateInterface</a></li>
124124
<li><a href="ex/ShapeType-class.html">ShapeType</a></li>
125125
<li><a href="ex/SpecializedDuration-class.html">SpecializedDuration</a></li>
126+
<li><a href="ex/WithGeneric-class.html">WithGeneric</a></li>
127+
<li><a href="ex/WithGenericSub-class.html">WithGenericSub</a></li>
126128

127129
<li class="section-title"><a href="ex/ex-library.html#exceptions">Exceptions</a></li>
128130
<li><a href="ex/MyError-class.html">MyError</a></li>

testing/test_package_docs/ex/COLOR-constant.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ <h5><a href="ex/ex-library.html">ex</a></h5>
116116
<li><a href="ex/PublicClassImplementsPrivateInterface-class.html">PublicClassImplementsPrivateInterface</a></li>
117117
<li><a href="ex/ShapeType-class.html">ShapeType</a></li>
118118
<li><a href="ex/SpecializedDuration-class.html">SpecializedDuration</a></li>
119+
<li><a href="ex/WithGeneric-class.html">WithGeneric</a></li>
120+
<li><a href="ex/WithGenericSub-class.html">WithGenericSub</a></li>
119121

120122
<li class="section-title"><a href="ex/ex-library.html#exceptions">Exceptions</a></li>
121123
<li><a href="ex/MyError-class.html">MyError</a></li>

testing/test_package_docs/ex/COLOR_GREEN-constant.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ <h5><a href="ex/ex-library.html">ex</a></h5>
116116
<li><a href="ex/PublicClassImplementsPrivateInterface-class.html">PublicClassImplementsPrivateInterface</a></li>
117117
<li><a href="ex/ShapeType-class.html">ShapeType</a></li>
118118
<li><a href="ex/SpecializedDuration-class.html">SpecializedDuration</a></li>
119+
<li><a href="ex/WithGeneric-class.html">WithGeneric</a></li>
120+
<li><a href="ex/WithGenericSub-class.html">WithGenericSub</a></li>
119121

120122
<li class="section-title"><a href="ex/ex-library.html#exceptions">Exceptions</a></li>
121123
<li><a href="ex/MyError-class.html">MyError</a></li>

testing/test_package_docs/ex/COLOR_ORANGE-constant.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ <h5><a href="ex/ex-library.html">ex</a></h5>
116116
<li><a href="ex/PublicClassImplementsPrivateInterface-class.html">PublicClassImplementsPrivateInterface</a></li>
117117
<li><a href="ex/ShapeType-class.html">ShapeType</a></li>
118118
<li><a href="ex/SpecializedDuration-class.html">SpecializedDuration</a></li>
119+
<li><a href="ex/WithGeneric-class.html">WithGeneric</a></li>
120+
<li><a href="ex/WithGenericSub-class.html">WithGenericSub</a></li>
119121

120122
<li class="section-title"><a href="ex/ex-library.html#exceptions">Exceptions</a></li>
121123
<li><a href="ex/MyError-class.html">MyError</a></li>

testing/test_package_docs/ex/COMPLEX_COLOR-constant.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ <h5><a href="ex/ex-library.html">ex</a></h5>
116116
<li><a href="ex/PublicClassImplementsPrivateInterface-class.html">PublicClassImplementsPrivateInterface</a></li>
117117
<li><a href="ex/ShapeType-class.html">ShapeType</a></li>
118118
<li><a href="ex/SpecializedDuration-class.html">SpecializedDuration</a></li>
119+
<li><a href="ex/WithGeneric-class.html">WithGeneric</a></li>
120+
<li><a href="ex/WithGenericSub-class.html">WithGenericSub</a></li>
119121

120122
<li class="section-title"><a href="ex/ex-library.html#exceptions">Exceptions</a></li>
121123
<li><a href="ex/MyError-class.html">MyError</a></li>

0 commit comments

Comments
 (0)