Skip to content

Commit eb90a44

Browse files
authored
Remove annotations from the features section of each element (#3268)
1 parent 1612637 commit eb90a44

31 files changed

+639
-325
lines changed

lib/src/generator/templates.aot_renderers_for_html.dart

Lines changed: 201 additions & 134 deletions
Large diffs are not rendered by default.

lib/src/generator/templates.aot_renderers_for_md.dart

Lines changed: 116 additions & 51 deletions
Large diffs are not rendered by default.

lib/src/model/field.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class Field extends ModelElement
114114

115115
@override
116116
Set<Feature> get features {
117-
var allFeatures = super.features..addAll(comboFeatures);
117+
var allFeatures = {...super.features, ...comboFeatures};
118118
// Combo features can indicate 'inherited' and 'override' if
119119
// either the getter or setter has one of those properties, but that's not
120120
// really specific enough for [Field]s that have public getter/setters.

lib/src/model/model_element.dart

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,12 @@ abstract class ModelElement extends Canonicalization
414414
@override
415415
late final ModelNode? modelNode = packageGraph.getModelNodeFor(element);
416416

417-
// Skips over annotations with null elements or that are otherwise
418-
// supposed to be invisible (@pragma). While technically, null elements
419-
// indicate invalid code from analyzer's perspective they are present in
420-
// sky_engine (@Native) so we don't want to crash here.
417+
/// This element's [Annotation]s.
418+
///
419+
/// Does not include annotations with `null` elements or that are otherwise
420+
/// supposed to be invisible (like `@pragma`). While `null` elements indicate
421+
/// invalid code from analyzer's perspective, some are present in `sky_engine`
422+
/// (`@Native`) so we don't want to crash here.
421423
late final List<Annotation> annotations = element.metadata
422424
.whereNot((m) =>
423425
m.element == null ||
@@ -458,24 +460,14 @@ abstract class ModelElement extends Canonicalization
458460
.where((s) => s.isNotEmpty)
459461
.toSet();
460462

461-
static const Set<String> _specialFeatures = {
462-
// Replace the @override annotation with a feature that explicitly
463-
// indicates whether an override has occurred.
464-
'override',
465-
// Drop the plain "deprecated" annotation; that's indicated via
466-
// strikethroughs. Custom @Deprecated() will still appear.
467-
'deprecated'
468-
};
469-
470463
bool get hasFeatures => features.isNotEmpty;
471464

472-
/// Usually a superset of [annotations] except where [_specialFeatures]
473-
/// replace them, a list of annotations as well as tags applied by
474-
/// Dartdoc itself when it notices characteristics of an element
475-
/// that need to be documented. See [Feature] for a list.
465+
/// The set of attributes or "features" of this element.
466+
///
467+
/// This includes tags applied by Dartdoc for various attributes that should
468+
/// be called out. See [Feature] for a list.
476469
Set<Feature> get features {
477470
return {
478-
...annotations.whereNot((a) => _specialFeatures.contains(a.name)),
479471
// 'const' and 'static' are not needed here because 'const' and 'static'
480472
// elements get their own sections in the doc.
481473
if (isFinal) Feature.finalFeature,

lib/templates/html/_accessor_getter.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
<section id="getter">
33

44
<section class="multi-line-signature">
5+
{{ >annotations }}
56
<span class="returntype">{{{ modelType.returnType.linkedName }}}</span>
6-
{{>name_summary}}
7-
{{>features}}
7+
{{ >name_summary }}
8+
{{ >features }}
89
</section>
910

1011
{{>documentation}}

lib/templates/html/_accessor_setter.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
<section id="setter">
33

44
<section class="multi-line-signature">
5+
{{ >annotations }}
56
<span class="returntype">void</span>
6-
{{>name_summary}}<span class="signature">(<wbr>{{{ linkedParamsNoMetadata }}})</span>
7-
{{>features}}
7+
{{ >name_summary }}<span class="signature">(<wbr>{{{ linkedParamsNoMetadata }}})</span>
8+
{{ >features }}
89
</section>
910

1011
{{>documentation}}

lib/templates/html/_annotations.html

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
{{ #hasAnnotations }}
2-
<dt>Annotations</dt>
3-
<dd>
4-
<ul class="annotation-list {{ relationshipsClass }}">
2+
<div>
3+
<ol class="annotation-list">
54
{{ #annotations }}
65
<li>{{{ linkedNameWithParameters }}}</li>
76
{{ /annotations }}
8-
</ul>
9-
</dd>
7+
</ol>
8+
</div>
109
{{ /hasAnnotations }}
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
{{#hasAnnotations}}
2-
<div>
3-
<ol class="annotation-list">
4-
{{#annotations}}
5-
<li>{{{linkedNameWithParameters}}}</li>
6-
{{/annotations}}
7-
</ol>
8-
</div>
9-
{{/hasAnnotations}}
1+
{{ >annotations }}
102

113
<span class="returntype">{{{ modelType.returnType.linkedName }}}</span>
124
{{>name_summary}}{{{genericParameters}}}(<wbr>{{#hasParameters}}{{{linkedParamsLines}}}{{/hasParameters}})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{{ #hasAnnotations }}
2+
<dt>Annotations</dt>
3+
<dd>
4+
<ul class="annotation-list {{ relationshipsClass }}">
5+
{{ #annotations }}
6+
<li>{{{ linkedNameWithParameters }}}</li>
7+
{{ /annotations }}
8+
</ul>
9+
</dd>
10+
{{ /hasAnnotations }}
11+

lib/templates/html/class.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
</ul></dd>
3434
{{/hasPotentiallyApplicableExtensions}}
3535

36-
{{ >annotations }}
36+
{{ >container_annotations }}
3737
</dl>
3838
</section>
3939
{{/hasModifiers}}

lib/templates/html/constructor.html

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,7 @@
77

88
{{#constructor}}
99
<section class="multi-line-signature">
10-
{{#hasAnnotations}}
11-
<div>
12-
<ol class="annotation-list">
13-
{{#annotations}}
14-
<li>{{{linkedNameWithParameters}}}</li>
15-
{{/annotations}}
16-
</ol>
17-
</div>
18-
{{/hasAnnotations}}
10+
{{ >annotations }}
1911
{{#isConst}}const{{/isConst}}
2012
<span class="name {{#isDeprecated}}deprecated{{/isDeprecated}}">{{{nameWithGenerics}}}</span>(<wbr>{{#hasParameters}}{{{linkedParamsLines}}}{{/hasParameters}})
2113
</section>

lib/templates/html/enum.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ <h1>
1919
{{ >super_chain }}
2020
{{ >interfaces }}
2121
{{ >mixed_in_types }}
22-
{{ >annotations }}
22+
{{ >container_annotations }}
2323
</dl>
2424
</section>
2525
{{ /hasModifiers }}

lib/templates/html/extension.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</ul>
1919
</dd>
2020
</dl>
21-
{{ >annotations }}
21+
{{ >container_annotations }}
2222
</section>
2323

2424
{{#hasPublicInstanceFields}}

lib/templates/html/function.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
{{#function}}
99
<section class="multi-line-signature">
10-
{{>callable_multiline}}
10+
{{ >callable_multiline }}
11+
{{ >features }}
1112
</section>
1213
{{>documentation}}
1314

lib/templates/html/library.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{{>head}}
22

33
<div id="dartdoc-main-content" class="main-content">
4+
{{ !-- TODO(srawlins): Add annotations. }}
45
{{#self}}
56
<div>{{>source_link}}<h1><span class="kind-library">{{{name}}}</span> {{kind}} {{>feature_set}} {{>categorization}}</h1></div>
67
{{/self}}

lib/templates/html/method.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
{{#method}}
99
<section class="multi-line-signature">
10-
{{>callable_multiline}}
11-
{{>features}}
10+
{{ >callable_multiline }}
11+
{{ >features }}
1212
</section>
1313
{{>documentation}}
1414

lib/templates/html/property.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
{{#self}}
99
{{#hasNoGetterSetter}}
1010
<section class="multi-line-signature">
11+
{{ >annotations }}
1112
{{{ modelType.linkedName }}}
12-
{{>name_summary}}
13-
{{>features}}
13+
{{ >name_summary }}
14+
{{ >features }}
1415
</section>
1516
{{>documentation}}
1617
{{>source_code}}

lib/templates/html/top_level_property.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
{{#hasNoGetterSetter}}
88
<section class="multi-line-signature">
9+
{{ >annotations }}
910
{{{ modelType.linkedName }}}
10-
{{>name_summary}}
11-
{{>features}}
11+
{{ >name_summary }}
12+
{{ >features }}
1213
</section>
1314
{{>documentation}}
1415
{{>source_code}}

lib/templates/md/_accessor_getter.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{{#getter}}
2-
{{{ modelType.returnType.linkedName }}} {{>name_summary}} {{!two spaces intentional}}
3-
{{>features}}
2+
{{ >annotations }}
3+
{{{ modelType.returnType.linkedName }}} {{ >name_summary }} {{ !two spaces intentional }}
4+
{{ >features }}
45

56
{{>documentation}}
67

lib/templates/md/_accessor_setter.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{{#setter}}
2-
{{>name_summary}}({{{ linkedParamsNoMetadata }}}) {{!two spaces intentional}}
3-
{{>features}}
2+
{{ >annotations }}
3+
{{ >name_summary }}({{{ linkedParamsNoMetadata }}}) {{ !two spaces intentional }}
4+
{{ >features }}
45

56
{{>documentation}}
67

lib/templates/md/function.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
{{/self}}
1010

1111
{{#function}}
12-
{{>callable_multiline}}
12+
{{ >callable_multiline }}
13+
{{ >features }}
1314

1415
{{>documentation}}
1516

lib/templates/md/library.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{{>head}}
22

33
{{#self}}
4+
{{ !-- TODO(srawlins): Add annotations. }}
45
# {{{ name }}} {{ kind }}
56

67
{{>source_link}}

lib/templates/md/property.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99

1010
{{#self}}
1111
{{#hasNoGetterSetter}}
12-
{{{ modelType.linkedName }}} {{>name_summary}} {{!two spaces intentional}}
13-
{{>features}}
12+
{{ >annotations }}
13+
{{{ modelType.linkedName }}} {{ >name_summary }} {{ !two spaces intentional }}
14+
{{ >features }}
1415

1516
{{>documentation}}
1617

lib/templates/md/top_level_property.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
{{>feature_set}}
99

1010
{{#hasNoGetterSetter}}
11-
{{{ modelType.linkedName }}} {{>name_summary}} {{!two spaces intentional}}
12-
{{>features}}
11+
{{ >annotations }}
12+
{{{ modelType.linkedName }}} {{ >name_summary }} {{ !two spaces intentional }}
13+
{{ >features }}
1314

1415
{{>documentation}}
1516

test/end2end/model_test.dart

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -190,23 +190,6 @@ void main() {
190190
mn.parameters
191191
.map((p) => p.annotations.first.linkedNameWithParameters),
192192
everyElement(equals(ab0)));
193-
194-
expect(genericMetadata.features.map((f) => f.linkedNameWithParameters),
195-
contains(ab0));
196-
expect(f.features.map((f) => f.linkedNameWithParameters), contains(ab0));
197-
expect(C.features.map((f) => f.linkedNameWithParameters), contains(ab0));
198-
expect(
199-
C.typeParameters.first.features
200-
.map((f) => f.linkedNameWithParameters),
201-
contains(ab0));
202-
expect(
203-
mp.parameters
204-
.map((p) => p.features.map((f) => f.linkedNameWithParameters)),
205-
everyElement(contains(ab0)));
206-
expect(
207-
mn.parameters
208-
.map((p) => p.features.map((f) => f.linkedNameWithParameters)),
209-
everyElement(contains(ab0)));
210193
});
211194
});
212195

@@ -3749,13 +3732,6 @@ String? topLevelFunction(int param1, bool param2, Cool coolBeans,
37493732
'```'));
37503733
});
37513734

3752-
test('annotations from getters and setters are accumulated in Fields', () {
3753-
expect(explicitGetterSetter.featuresAsString,
3754-
contains('a Getter Annotation'));
3755-
expect(explicitGetterSetter.featuresAsString,
3756-
contains('a Setter Annotation'));
3757-
});
3758-
37593735
test('Docs from inherited implicit accessors are preserved', () {
37603736
expect(
37613737
explicitGetterImplicitSetter.setter!.documentationComment, isNot(''));

test/src/utils.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,22 @@ extension ModelElementIterableExtensions<T extends ModelElement>
360360
T named(String name) => firstWhere((e) => e.name == name);
361361
}
362362

363+
extension IterableStringExtensions on Iterable<String> {
364+
/// The main content line of `this`.
365+
Iterable<String> get mainContent =>
366+
skipWhile((line) => !line.contains('"dartdoc-main-content"'))
367+
.takeWhile((line) => !line.contains('/.main-content'));
368+
369+
/// Verifies that [mainContent] contains [matchers] in order.
370+
void expectMainContentContainsAllInOrder(Iterable<Object?> matchers) {
371+
expect(
372+
mainContent,
373+
containsAllInOrder(matchers),
374+
reason: 'main content:\n\n${mainContent.join('\n')}',
375+
);
376+
}
377+
}
378+
363379
/// Extension methods just for tests.
364380
extension on ResourceProvider {
365381
Future<void> writeDartdocResource(String path, String content) async {

test/templates/category_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ typedef T2 = T1;
131131
});
132132

133133
test('category page links to classes annotated with category', () async {
134+
// TODO(srawlins): Use expectMainContentContainsAllInOrder throughout.
134135
expect(
135136
topicOneLines,
136137
containsAllInOrder([

0 commit comments

Comments
 (0)