Skip to content

Commit ca8441d

Browse files
committed
don't generate links for inherited methods/properties/operators. also add a link checker for the CI build
Closes #750 Closes #752 Closes #751 Closes #749 Closes #717 LGTM given by: @devoncarew Squashed commit of the following: commit 9204df1 Author: Seth Ladd <[email protected]> Date: Thu Jul 30 20:17:30 2015 -0700 remove comments commit 3ff90dc Author: Seth Ladd <[email protected]> Date: Thu Jul 30 20:12:14 2015 -0700 fix checked mode error commit 4935a85 Author: Seth Ladd <[email protected]> Date: Thu Jul 30 20:03:11 2015 -0700 try to put classes into libraries that export them commit 21b5952 Author: Seth Ladd <[email protected]> Date: Thu Jul 30 17:08:31 2015 -0700 no longer generating links to an enums index property commit 1f2a401 Author: Seth Ladd <[email protected]> Date: Thu Jul 30 16:07:36 2015 -0700 fix bug with linking to return type originally from an exported library commit 39fcabc Author: Seth Ladd <[email protected]> Date: Thu Jul 30 14:30:43 2015 -0700 fix bug for 404s commit a473e7a Author: Seth Ladd <[email protected]> Date: Thu Jul 30 14:07:40 2015 -0700 add check-links to the travis build commit e4b9ffa Author: Seth Ladd <[email protected]> Date: Thu Jul 30 13:59:59 2015 -0700 don't generate links for inherited methods/properties/operators. also add a link checker for the CI build
1 parent af002c6 commit ca8441d

File tree

12 files changed

+201
-81
lines changed

12 files changed

+201
-81
lines changed

lib/resources/styles.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ footer .container-fluid {
331331
background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'><path fill='#FFFFFF' d='M6.7,4L5.7,4.9L8.8,8l-3.1,3.1L6.7,12l4-4L6.7,4z'/></svg>");
332332
background-position: center;
333333
content: "\00a0";
334-
margin: 0 16px 0 12px;
334+
margin: 0 6px 0 4px;
335335
}
336336

337337
.gt-separated.dark li:before {

lib/src/html_generator.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ class Templates {
8989
'name_summary',
9090
'sidebar_for_class',
9191
'source_code',
92-
'sidebar_for_library'
92+
'sidebar_for_library',
93+
'name_link'
9394
];
9495

9596
for (var partial in partials) {

lib/src/model.dart

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ abstract class ModelElement implements Comparable {
253253
(this is Library) ? (this as Library).package : this.library.package;
254254

255255
String get linkedName {
256-
if (!package.isDocumented(this)) {
256+
if (!package.isDocumented(this.element)) {
257257
return htmlEscape(name);
258258
}
259259
if (name.startsWith('_')) {
@@ -267,7 +267,7 @@ abstract class ModelElement implements Comparable {
267267
return '<a href="${href}">$name</a>';
268268
}
269269

270-
String get href => package.isDocumented(this) ? _href : null;
270+
String get href => package.isDocumented(this.element) ? _href : null;
271271

272272
String get _href;
273273

@@ -407,17 +407,16 @@ class Package {
407407

408408
String toString() => isSdk ? 'SDK' : 'Package $name';
409409

410-
bool isDocumented(ModelElement e) {
411-
if (e is Library) {
412-
return _libraries.any((lib) => lib.element == e.element);
410+
bool isDocumented(Element element) {
411+
if (element is LibraryElement) {
412+
return _libraries.any((lib) => lib.element == element);
413413
}
414414

415415
Element el;
416-
if (e.element is ClassMemberElement ||
417-
e.element is PropertyAccessorElement) {
418-
el = e.element.enclosingElement;
419-
} else if (e.element is TopLevelVariableElement) {
420-
TopLevelVariableElement variable = (e.element as TopLevelVariableElement);
416+
if (element is ClassMemberElement || element is PropertyAccessorElement) {
417+
el = element.enclosingElement;
418+
} else if (element is TopLevelVariableElement) {
419+
TopLevelVariableElement variable = (element as TopLevelVariableElement);
421420
if (variable.getter != null) {
422421
el = variable.getter;
423422
} else if (variable.setter != null) {
@@ -426,7 +425,7 @@ class Package {
426425
el = variable;
427426
}
428427
} else {
429-
el = e.element;
428+
el = element;
430429
}
431430
return _libraries.any((lib) => lib.hasInNamespace(el));
432431
}
@@ -709,7 +708,8 @@ class Class extends ModelElement {
709708
}).where((mixin) => mixin != null).toList(growable: false);
710709

711710
if (_cls.supertype != null && _cls.supertype.element.supertype != null) {
712-
var lib = new Library(_cls.supertype.element.library, p);
711+
Library lib = package._getLibraryFor(_cls.supertype.element);
712+
713713
_supertype = new ElementType(
714714
_cls.supertype, new ModelElement.from(_cls.supertype.element, lib));
715715

@@ -817,6 +817,7 @@ class Class extends ModelElement {
817817
_instanceFields = _allFields
818818
.where((f) => !f.isStatic)
819819
.toList(growable: false)..sort(byName);
820+
820821
return _instanceFields;
821822
}
822823

@@ -1138,11 +1139,18 @@ class Enum extends Class {
11381139
_constants = _cls.fields
11391140
.where(isPublic)
11401141
.where((f) => f.isConst)
1141-
.map((field) => new EnumField(index++, field, library))
1142+
.map((field) => new EnumField.forConstant(index++, field, library))
11421143
.toList(growable: false)..sort(byName);
11431144

11441145
return _constants;
11451146
}
1147+
1148+
@override
1149+
List<EnumField> get instanceProperties {
1150+
return super.instanceProperties
1151+
.map((Field p) => new EnumField(p.element, p.library))
1152+
.toList(growable: false);
1153+
}
11461154
}
11471155

11481156
abstract class SourceCodeMixin {
@@ -1311,17 +1319,19 @@ class Field extends ModelElement {
13111319
/// Enum's fields are virtual, so we do a little work to create
13121320
/// usable values for the docs.
13131321
class EnumField extends Field {
1314-
final int index;
1322+
int _index;
13151323

1316-
EnumField(this.index, FieldElement element, Library library)
1324+
EnumField.forConstant(this._index, FieldElement element, Library library)
13171325
: super(element, library);
13181326

1327+
EnumField(FieldElement element, Library library) : super(element, library);
1328+
13191329
@override
13201330
String get constantValue {
13211331
if (name == 'values') {
13221332
return 'const List&lt;${_field.enclosingElement.name}&gt;';
13231333
} else {
1324-
return 'const ${_field.enclosingElement.name}($index)';
1334+
return 'const ${_field.enclosingElement.name}($_index)';
13251335
}
13261336
}
13271337

@@ -1631,8 +1641,9 @@ class ElementType {
16311641
ElementType get _returnType {
16321642
var rt = (_type as FunctionType).returnType;
16331643
return new ElementType(rt, new ModelElement.from(
1634-
rt.element, new Library(rt.element.library, _element.package)));
1644+
rt.element, new Library(_element.library.element, _element.package)));
16351645
}
1646+
16361647
ModelElement get returnElement {
16371648
Element e = (_type as FunctionType).returnType.element;
16381649
if (e == null) {

lib/templates/_callable.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<dt id="{{htmlId}}" class="callable">
2-
<a href="{{href}}">{{>name_summary}}</a><span class="signature">(<wbr>{{{ linkedParamsNoMetadata }}})
2+
{{#isInherited}}{{>name_summary}}{{/isInherited}}{{^isInherited}}<a href="{{href}}">{{>name_summary}}</a>{{/isInherited}}<span class="signature">(<wbr>{{{ linkedParamsNoMetadata }}})
33
&#8594;
44
<span class="returntype">{{{ linkedReturnType }}}</span>
55
</span>

lib/templates/_name_link.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{#isInherited}}{{name}}{{/isInherited}}{{^isInherited}}{{{linkedName}}}{{/isInherited}}

lib/templates/_property.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<dt id="{{htmlId}}" class="property">
22
<span class="top-level-variable-type">{{{ linkedReturnType }}}</span>
3-
<a href="{{href}}">{{>name_summary}}</a>
3+
{{#isInherited}}{{>name_summary}}{{/isInherited}}{{^isInherited}}{{{linkedName}}}{{/isInherited}}
44
</dt>
55
<dd>
66
{{>readable_writable}}

lib/templates/_sidebar_for_class.html

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
1-
<ol>
2-
{{#class.hasConstants}}
3-
<li class="section-title"><a href="{{class.href}}#constants">Constants</a></li>
4-
{{#class.constants}}
5-
<li><a href="{{href}}">{{name}}</a></li>
6-
{{/class.constants}}
7-
{{/class.hasConstants}}
1+
<ol>
2+
{{#class.hasConstants}}
3+
<li class="section-title"><a href="{{class.href}}#constants">Constants</a></li>
4+
{{#class.constants}}
5+
<li>{{{linkedName}}}</li>
6+
{{/class.constants}}
7+
{{/class.hasConstants}}
88

9-
{{#class.hasStaticProperties}}
10-
<li class="section-title"><a href="{{class.href}}#static-properties">Static properties</a></li>
11-
{{#class.staticProperties}}
12-
<li><a href="{{href}}">{{name}}</a></li>
13-
{{/class.staticProperties}}
14-
{{/class.hasStaticProperties}}
9+
{{#class.hasStaticProperties}}
10+
<li class="section-title"><a href="{{class.href}}#static-properties">Static properties</a></li>
11+
{{#class.staticProperties}}
12+
<li><a href="{{href}}">{{name}}</a></li>
13+
{{/class.staticProperties}}
14+
{{/class.hasStaticProperties}}
1515

16-
{{#class.hasStaticMethods}}
17-
<li class="section-title"><a href="{{class.href}}#static-methods">Static methods</a></li>
18-
{{#class.staticMethods}}
19-
<li><a href="{{href}}">{{name}}</a></li>
20-
{{/class.staticMethods}}
21-
{{/class.hasStaticMethods}}
16+
{{#class.hasStaticMethods}}
17+
<li class="section-title"><a href="{{class.href}}#static-methods">Static methods</a></li>
18+
{{#class.staticMethods}}
19+
<li><a href="{{href}}">{{name}}</a></li>
20+
{{/class.staticMethods}}
21+
{{/class.hasStaticMethods}}
2222

23-
{{#class.hasInstanceProperties}}
24-
<li class="section-title"><a href="{{class.href}}#instance-properties">Properties</a></li>
25-
{{#class.allInstanceProperties}}
26-
<li><a href="{{href}}">{{name}}</a></li>
27-
{{/class.allInstanceProperties}}
28-
{{/class.hasInstanceProperties}}
23+
{{#class.hasInstanceProperties}}
24+
<li class="section-title"><a href="{{class.href}}#instance-properties">Properties</a></li>
25+
{{#class.allInstanceProperties}}
26+
<li>{{>name_link}}</li>
27+
{{/class.allInstanceProperties}}
28+
{{/class.hasInstanceProperties}}
2929

30-
{{#class.hasConstructors}}
31-
<li class="section-title"><a href="{{class.href}}#constructors">Constructors</a></li>
32-
{{#class.constructors}}
33-
<li><a href="{{href}}">{{shortName}}</a></li>
34-
{{/class.constructors}}
35-
{{/class.hasConstructors}}
30+
{{#class.hasConstructors}}
31+
<li class="section-title"><a href="{{class.href}}#constructors">Constructors</a></li>
32+
{{#class.constructors}}
33+
<li><a href="{{href}}">{{shortName}}</a></li>
34+
{{/class.constructors}}
35+
{{/class.hasConstructors}}
3636

37-
{{#class.hasOperators}}
38-
<li class="section-title"><a href="{{class.href}}#operators">Operators</a></li>
39-
{{#class.allOperators}}
40-
<li><a href="{{href}}">{{name}}</a></li>
41-
{{/class.allOperators}}
42-
{{/class.hasOperators}}
37+
{{#class.hasOperators}}
38+
<li class="section-title"><a href="{{class.href}}#operators">Operators</a></li>
39+
{{#class.allOperators}}
40+
<li>{{>name_link}}</li>
41+
{{/class.allOperators}}
42+
{{/class.hasOperators}}
4343

44-
{{#class.hasMethods}}
45-
<li class="section-title"><a href="{{class.href}}#methods">Methods</a></li>
46-
{{#class.allInstanceMethods}}
47-
<li><a href="{{href}}">{{name}}</a></li>
48-
{{/class.allInstanceMethods}}
49-
{{/class.hasMethods}}
50-
</ol>
44+
{{#class.hasMethods}}
45+
<li class="section-title"><a href="{{class.href}}#methods">Methods</a></li>
46+
{{#class.allInstanceMethods}}
47+
<li>{{>name_link}}</li>
48+
{{/class.allInstanceMethods}}
49+
{{/class.hasMethods}}
50+
</ol>

0 commit comments

Comments
 (0)