Skip to content

Commit 5244b97

Browse files
committed
Merge pull request #689 from keertip/docs
get documentation for properties
2 parents c842455 + 0ab8f71 commit 5244b97

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

lib/src/model.dart

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ abstract class ModelElement implements Comparable {
106106
}
107107
}
108108

109+
String get _computeDocumentationComment =>
110+
element.computeDocumentationComment();
111+
109112
String get documentation {
110113
if (_documentation != null) {
111114
return _documentation;
@@ -115,7 +118,7 @@ abstract class ModelElement implements Comparable {
115118
return null;
116119
}
117120

118-
_documentation = element.computeDocumentationComment();
121+
_documentation = _computeDocumentationComment;
119122

120123
if (_documentation == null && canOverride()) {
121124
var overrideElement = overriddenElement;
@@ -1106,6 +1109,16 @@ class Field extends ModelElement {
11061109
_setModelType();
11071110
}
11081111

1112+
@override
1113+
String get _computeDocumentationComment {
1114+
if (hasGetter) {
1115+
return _field.getter.computeDocumentationComment();
1116+
} else if (hasSetter) {
1117+
return _field.setter.computeDocumentationComment();
1118+
}
1119+
return _field.computeDocumentationComment();
1120+
}
1121+
11091122
void _setModelType() {
11101123
if (hasGetter) {
11111124
var t = _field.getter.returnType;
@@ -1362,6 +1375,16 @@ class TopLevelVariable extends ModelElement {
13621375

13631376
String get linkedReturnType => modelType.linkedName;
13641377

1378+
@override
1379+
String get _computeDocumentationComment {
1380+
if (hasGetter) {
1381+
return _variable.getter.computeDocumentationComment();
1382+
} else if (hasSetter) {
1383+
return _variable.setter.computeDocumentationComment();
1384+
}
1385+
return _variable.computeDocumentationComment();
1386+
}
1387+
13651388
String get constantValue {
13661389
var v = (_variable as ConstTopLevelVariableElementImpl).node.toSource();
13671390
if (v == null) return '';

test/model_test.dart

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,13 +460,19 @@ void main() {
460460
});
461461

462462
group('Field', () {
463-
var c, f1, f2, constField;
463+
var c, f1, f2, constField, dynamicGetter, onlySetter, LongFirstLine;
464464

465465
setUp(() {
466466
c = exLibrary.classes.firstWhere((c) => c.name == 'Apple');
467467
f1 = c.staticProperties[0]; // n
468468
f2 = c.instanceProperties[0];
469469
constField = c.constants[0]; // string
470+
LongFirstLine =
471+
fakeLibrary.classes.firstWhere((c) => c.name == 'LongFirstLine');
472+
dynamicGetter = LongFirstLine.instanceProperties
473+
.firstWhere((p) => p.name == 'dynamicGetter');
474+
onlySetter = LongFirstLine.instanceProperties
475+
.firstWhere((p) => p.name == 'onlySetter');
470476
});
471477

472478
test('is not const', () {
@@ -484,15 +490,29 @@ void main() {
484490
test('is not static', () {
485491
expect(f2.isStatic, isFalse);
486492
});
493+
494+
test('getter documentation', () {
495+
expect(dynamicGetter.documentation,
496+
equals('Dynamic getter. Readable only.'));
497+
});
498+
499+
test('setter documentation', () {
500+
expect(onlySetter.documentation,
501+
equals('Only a setter, with a single param, of type double.'));
502+
});
487503
});
488504

489505
group('Variable', () {
490506
TopLevelVariable v;
491-
TopLevelVariable v3;
507+
TopLevelVariable v3, justGetter, justSetter;
492508

493509
setUp(() {
494510
v = exLibrary.properties.firstWhere((p) => p.name == 'number');
495511
v3 = exLibrary.properties.firstWhere((p) => p.name == 'y');
512+
justGetter =
513+
fakeLibrary.properties.firstWhere((p) => p.name == 'justGetter');
514+
justSetter =
515+
fakeLibrary.properties.firstWhere((p) => p.name == 'justSetter');
496516
});
497517

498518
test('found two properties', () {
@@ -506,6 +526,16 @@ void main() {
506526
test('linked return type is dynamic', () {
507527
expect(v3.linkedReturnType, 'dynamic');
508528
});
529+
530+
test('getter documentation', () {
531+
expect(justGetter.documentation,
532+
equals('Just a getter. No partner setter.'));
533+
});
534+
535+
test('setter documentation', () {
536+
expect(justSetter.documentation,
537+
equals('Just a setter. No partner getter.'));
538+
});
509539
});
510540

511541
group('Constant', () {

0 commit comments

Comments
 (0)