Skip to content

Commit 38a7863

Browse files
astashovdevoncarew
authored andcommitted
Add showing docs of overridden accessors [#1266] (#1297)
For methods, in case there's a method, which overrides another method, and it doesn't have docs, we show the docs from the overridden method. @Hixie noticed we don't do the same thing for accessors. He and @devoncarew think we should do the same for accessors as well. This commit adds that functionality.
1 parent 10d0b6b commit 38a7863

34 files changed

+353
-17
lines changed

lib/src/model.dart

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,22 @@ class Accessor extends ModelElement
102102

103103
bool get isGetter => _accessor.isGetter;
104104

105+
@override
106+
Accessor get overriddenElement {
107+
Element parent = element.enclosingElement;
108+
if (parent is ClassElement) {
109+
for (InterfaceType t in getAllSupertypes(parent)) {
110+
var accessor = this.isGetter
111+
? t.getGetter(element.name)
112+
: t.getSetter(element.name);
113+
if (accessor != null) {
114+
return new Accessor(accessor, library);
115+
}
116+
}
117+
}
118+
return null;
119+
}
120+
105121
@override
106122
String get kind => 'accessor';
107123

@@ -1548,7 +1564,7 @@ abstract class ModelElement implements Comparable, Nameable, Documentable {
15481564
return __documentation;
15491565
}
15501566

1551-
bool canOverride() => element is ClassMemberElement;
1567+
bool canOverride() => element is ClassMemberElement || element is PropertyAccessorElement;
15521568

15531569
@override
15541570
int compareTo(dynamic other) {

test/model_test.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,8 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
11961196
onlySetterGetter,
11971197
onlySetterSetter;
11981198

1199+
Class classB;
1200+
11991201
setUp(() {
12001202
TopLevelVariable justGetter =
12011203
fakeLibrary.properties.firstWhere((p) => p.name == 'justGetter');
@@ -1205,6 +1207,8 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
12051207
fakeLibrary.properties.firstWhere((p) => p.name == 'justSetter');
12061208
onlySetterSetter = justSetter.setter;
12071209
onlySetterGetter = justSetter.getter;
1210+
1211+
classB = exLibrary.classes.singleWhere((c) => c.name == 'B');
12081212
});
12091213

12101214
test('are available on top-level variables', () {
@@ -1213,6 +1217,11 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
12131217
expect(onlySetterGetter, isNull);
12141218
expect(onlySetterSetter.name, equals('justSetter='));
12151219
});
1220+
1221+
test('if overridden, gets documentation from superclasses', () {
1222+
final doc = classB.allInstanceProperties.firstWhere((p) => p.name == "s").getter.documentation;
1223+
expect(doc, equals("The getter for `s`"));
1224+
});
12161225
});
12171226

12181227
group('Top-level Variable', () {

testing/test_package/lib/example.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ class B extends Apple with Cat {
151151
@override
152152
bool get isImplemented => false;
153153

154+
@override
155+
String get s => "123";
156+
154157
@deprecated
155158
Future doNothing() async {}
156159

testing/test_package_docs/ex/B-class.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,16 @@ <h2>Properties</h2>
239239
<div class="features">
240240
read-only, inherited
241241
</div>
242+
</dd>
243+
<dt id="s" class="property">
244+
<span class="name"><a href="ex/B/s.html">s</a></span>
245+
<span class="signature">&#8594; String</span>
246+
</dt>
247+
<dd>
248+
<p></p>
249+
<div class="features">
250+
read-only
251+
</div>
242252
</dd>
243253
<dt id="s" class="property inherited">
244254
<span class="name"><a href="ex/Apple/s.html">s</a></span>
@@ -389,6 +399,7 @@ <h5>B</h5>
389399
<li><a href="ex/B/list.html">list</a></li>
390400
<li class="inherited"><a href="ex/Apple/m.html">m</a></li>
391401
<li class="inherited"><a href="ex/B/runtimeType.html">runtimeType</a></li>
402+
<li><a href="ex/B/s.html">s</a></li>
392403
<li class="inherited"><a href="ex/Apple/s.html">s</a></li>
393404

394405
<li class="section-title inherited"><a href="ex/B-class.html#operators">Operators</a></li>

testing/test_package_docs/ex/B/B.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ <h5><a href="ex/B-class.html">B</a></h5>
8989
<li><a href="ex/B/list.html">list</a></li>
9090
<li class="inherited"><a href="ex/Apple/m.html">m</a></li>
9191
<li class="inherited"><a href="ex/B/runtimeType.html">runtimeType</a></li>
92+
<li><a href="ex/B/s.html">s</a></li>
9293
<li class="inherited"><a href="ex/Apple/s.html">s</a></li>
9394

9495
<li class="section-title inherited"><a href="ex/B-class.html#operators">Operators</a></li>

testing/test_package_docs/ex/B/abstractMethod.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ <h5><a href="ex/B-class.html">B</a></h5>
8888
<li><a href="ex/B/list.html">list</a></li>
8989
<li class="inherited"><a href="ex/Apple/m.html">m</a></li>
9090
<li class="inherited"><a href="ex/B/runtimeType.html">runtimeType</a></li>
91+
<li><a href="ex/B/s.html">s</a></li>
9192
<li class="inherited"><a href="ex/Apple/s.html">s</a></li>
9293

9394
<li class="section-title inherited"><a href="ex/B-class.html#operators">Operators</a></li>

testing/test_package_docs/ex/B/autoCompress.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ <h5><a href="ex/B-class.html">B</a></h5>
8888
<li><a href="ex/B/list.html">list</a></li>
8989
<li class="inherited"><a href="ex/Apple/m.html">m</a></li>
9090
<li class="inherited"><a href="ex/B/runtimeType.html">runtimeType</a></li>
91+
<li><a href="ex/B/s.html">s</a></li>
9192
<li class="inherited"><a href="ex/Apple/s.html">s</a></li>
9293

9394
<li class="section-title inherited"><a href="ex/B-class.html#operators">Operators</a></li>

testing/test_package_docs/ex/B/doNothing.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ <h5><a href="ex/B-class.html">B</a></h5>
8888
<li><a href="ex/B/list.html">list</a></li>
8989
<li class="inherited"><a href="ex/Apple/m.html">m</a></li>
9090
<li class="inherited"><a href="ex/B/runtimeType.html">runtimeType</a></li>
91+
<li><a href="ex/B/s.html">s</a></li>
9192
<li class="inherited"><a href="ex/Apple/s.html">s</a></li>
9293

9394
<li class="section-title inherited"><a href="ex/B-class.html#operators">Operators</a></li>

testing/test_package_docs/ex/B/hashCode.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ <h5><a href="ex/B-class.html">B</a></h5>
8888
<li><a href="ex/B/list.html">list</a></li>
8989
<li class="inherited"><a href="ex/Apple/m.html">m</a></li>
9090
<li class="inherited"><a href="ex/B/runtimeType.html">runtimeType</a></li>
91+
<li><a href="ex/B/s.html">s</a></li>
9192
<li class="inherited"><a href="ex/Apple/s.html">s</a></li>
9293

9394
<li class="section-title inherited"><a href="ex/B-class.html#operators">Operators</a></li>

testing/test_package_docs/ex/B/isImplemented.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ <h5><a href="ex/B-class.html">B</a></h5>
8888
<li><a href="ex/B/list.html">list</a></li>
8989
<li class="inherited"><a href="ex/Apple/m.html">m</a></li>
9090
<li class="inherited"><a href="ex/B/runtimeType.html">runtimeType</a></li>
91+
<li><a href="ex/B/s.html">s</a></li>
9192
<li class="inherited"><a href="ex/Apple/s.html">s</a></li>
9293

9394
<li class="section-title inherited"><a href="ex/B-class.html#operators">Operators</a></li>

0 commit comments

Comments
 (0)