Skip to content

Commit abed7ac

Browse files
committed
Merge pull request #696 from dart-lang/combo-field
put docs for getters and setters together
2 parents 9e37155 + 5710103 commit abed7ac

File tree

5 files changed

+28
-8
lines changed

5 files changed

+28
-8
lines changed

.analysis_options

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22

33
analyzer:
44
exclude:
5+
- test_package/doc/api
56
- test_package_bad/
67
- doc/api/

lib/src/model.dart

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,12 +1161,21 @@ class Field extends ModelElement {
11611161

11621162
@override
11631163
String get _computeDocumentationComment {
1164+
var buffer = new StringBuffer();
11641165
if (hasGetter) {
1165-
return _field.getter.computeDocumentationComment();
1166-
} else if (hasSetter) {
1167-
return _field.setter.computeDocumentationComment();
1166+
buffer.write(_field.getter.computeDocumentationComment());
1167+
}
1168+
1169+
if (hasSetter) {
1170+
if (buffer.isNotEmpty) buffer.write('\n\n');
1171+
buffer.write(_field.setter.computeDocumentationComment());
1172+
}
1173+
1174+
if (buffer.isEmpty) {
1175+
buffer.write(_field.computeDocumentationComment());
1176+
} else {
1177+
return buffer.toString();
11681178
}
1169-
return _field.computeDocumentationComment();
11701179
}
11711180

11721181
void _setModelType() {

lib/templates/_documentation.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
<section class="desc markdown">
32

43
{{^hasDocumentation}}

test/model_test.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,9 @@ void main() {
469469
});
470470

471471
group('Field', () {
472-
var c, f1, f2, constField, dynamicGetter, onlySetter, LongFirstLine;
472+
Class c, LongFirstLine;
473+
Field f1, f2, constField, dynamicGetter, onlySetter;
474+
Field lengthX;
473475

474476
setUp(() {
475477
c = exLibrary.classes.firstWhere((c) => c.name == 'Apple');
@@ -482,6 +484,10 @@ void main() {
482484
.firstWhere((p) => p.name == 'dynamicGetter');
483485
onlySetter = LongFirstLine.instanceProperties
484486
.firstWhere((p) => p.name == 'onlySetter');
487+
488+
lengthX = fakeLibrary.classes.firstWhere(
489+
(c) => c.name == 'WithGetterAndSetter').allInstanceProperties
490+
.firstWhere((c) => c.name == 'lengthX');
485491
});
486492

487493
test('is not const', () {
@@ -509,6 +515,11 @@ void main() {
509515
expect(onlySetter.documentation,
510516
equals('Only a setter, with a single param, of type double.'));
511517
});
518+
519+
test('explicit getter and setter docs are unified', () {
520+
expect(lengthX.documentation, contains('Sets the length.'));
521+
expect(lengthX.documentation, contains('Returns a length.'));
522+
});
512523
});
513524

514525
group('Variable', () {

test_package/lib/fake.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,10 @@ class WithGetterAndSetter {
334334
/// Returns a length.
335335
///
336336
/// Throws some exception if used in the fourth dimension.
337-
int get length => 1;
337+
int get lengthX => 1;
338338

339339
/// Sets the length.
340340
///
341341
/// Throws if set to an imaginary number.
342-
void set length(int _length) {}
342+
void set lengthX(int _length) {}
343343
}

0 commit comments

Comments
 (0)