Skip to content

Commit 3c7eea8

Browse files
committed
display named constructor only in left nav
add tests for shortname
1 parent 6f9fdb3 commit 3c7eea8

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

lib/src/model.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,14 @@ class Constructor extends ModelElement {
12041204

12051205
bool get isConst => _constructor.isConst;
12061206

1207+
String get shortName {
1208+
if (name.contains('.')) {
1209+
return name.substring(_constructor.enclosingElement.name.length + 1);
1210+
} else {
1211+
return name;
1212+
}
1213+
}
1214+
12071215
@override
12081216
String get name {
12091217
String constructorName = element.name;

lib/templates/class.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
{{#class.hasConstructors}}
3939
<li class="section-title"><a href="#constructors">Constructors</a></li>
4040
{{#class.constructors}}
41-
<li><a href="{{href}}">{{name}}</a></li>
41+
<li><a href="{{href}}">{{shortName}}</a></li>
4242
{{/class.constructors}}
4343
{{/class.hasConstructors}}
4444

test/model_test.dart

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,14 +544,24 @@ void main() {
544544
});
545545

546546
group('Constructor', () {
547-
var c2;
547+
Constructor appleDefaultConstructor;
548+
Constructor appleConstructorFromString;
548549
setUp(() {
549-
c2 = exLibrary.classes.firstWhere((c) => c.name == 'Apple').constructors[
550-
0];
550+
Class apple = exLibrary.classes.firstWhere((c) => c.name == 'Apple');
551+
appleDefaultConstructor =
552+
apple.constructors.firstWhere((c) => c.name == 'Apple');
553+
appleConstructorFromString =
554+
apple.constructors.firstWhere((c) => c.name == 'Apple.fromString');
551555
});
552556

553557
test('has contructor', () {
554-
expect(c2, isNotNull);
558+
expect(appleDefaultConstructor, isNotNull);
559+
expect(appleDefaultConstructor.name, equals('Apple'));
560+
expect(appleDefaultConstructor.shortName, equals('Apple'));
561+
});
562+
563+
test('shortName', () {
564+
expect(appleConstructorFromString.shortName, equals('fromString'));
555565
});
556566
});
557567

0 commit comments

Comments
 (0)