Skip to content

Commit 7a5ecb7

Browse files
committed
Model: improve isDeprecated calculation for properties
Closes #1050
1 parent a62ef0c commit 7a5ecb7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+164
-141
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 0.8.4
22
* [enhancement] Only include generator metadata in the package `index.html` file.
3+
* [bug] Fixed the display of deprecated properties.
34

45
## 0.8.3
56
* [enhancement] Added `--[no-]include-source` option.

lib/src/model.dart

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,29 @@ abstract class ModelElement implements Comparable, Nameable, Documentable {
302302

303303
bool get isConst => false;
304304

305-
bool get isDeprecated => element.metadata.any((a) => a.isDeprecated);
305+
bool get isDeprecated {
306+
// If element.metadata is empty, it might be because this is a property
307+
// where the metadata belongs to the individual getter/setter
308+
if (element.metadata.isEmpty && element is PropertyInducingElement) {
309+
var pie = element as PropertyInducingElement;
310+
311+
// The getter or the setter might be null – so the stored value may be
312+
// `true`, `false`, or `null`
313+
var getterDeprecated = pie.getter?.metadata?.any((a) => a.isDeprecated);
314+
var setterDeprecated = pie.setter?.metadata?.any((a) => a.isDeprecated);
315+
316+
var deprecatedValues =
317+
[getterDeprecated, setterDeprecated].where((a) => a != null).toList();
318+
319+
// At least one of these should be non-null. Otherwise things are weird
320+
assert(deprecatedValues.isNotEmpty);
321+
322+
// If there are both a setter and getter, only show the property as
323+
// deprecated if both are deprecated.
324+
return deprecatedValues.every((d) => d);
325+
}
326+
return element.metadata.any((a) => a.isDeprecated);
327+
}
306328

307329
ElementType get modelType => _modelType;
308330

test_package_docs/ex/Animal-class.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ <h5><a href="ex/ex-library.html">ex</a></h5>
8989

9090
<li class="section-title"><a href="ex/ex-library.html#properties">Properties</a></li>
9191
<li><a class="deprecated" href="ex/deprecatedField.html">deprecatedField</a></li>
92-
<li><a href="ex/deprecatedGetter.html">deprecatedGetter</a></li>
93-
<li><a href="ex/deprecatedSetter.html">deprecatedSetter</a></li>
92+
<li><a class="deprecated" href="ex/deprecatedGetter.html">deprecatedGetter</a></li>
93+
<li><a class="deprecated" href="ex/deprecatedSetter.html">deprecatedSetter</a></li>
9494
<li><a href="ex/number.html">number</a></li>
9595
<li><a href="ex/y.html">y</a></li>
9696

test_package_docs/ex/Apple-class.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ <h5><a href="ex/ex-library.html">ex</a></h5>
9393

9494
<li class="section-title"><a href="ex/ex-library.html#properties">Properties</a></li>
9595
<li><a class="deprecated" href="ex/deprecatedField.html">deprecatedField</a></li>
96-
<li><a href="ex/deprecatedGetter.html">deprecatedGetter</a></li>
97-
<li><a href="ex/deprecatedSetter.html">deprecatedSetter</a></li>
96+
<li><a class="deprecated" href="ex/deprecatedGetter.html">deprecatedGetter</a></li>
97+
<li><a class="deprecated" href="ex/deprecatedSetter.html">deprecatedSetter</a></li>
9898
<li><a href="ex/number.html">number</a></li>
9999
<li><a href="ex/y.html">y</a></li>
100100

test_package_docs/ex/B-class.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ <h5><a href="ex/ex-library.html">ex</a></h5>
9191

9292
<li class="section-title"><a href="ex/ex-library.html#properties">Properties</a></li>
9393
<li><a class="deprecated" href="ex/deprecatedField.html">deprecatedField</a></li>
94-
<li><a href="ex/deprecatedGetter.html">deprecatedGetter</a></li>
95-
<li><a href="ex/deprecatedSetter.html">deprecatedSetter</a></li>
94+
<li><a class="deprecated" href="ex/deprecatedGetter.html">deprecatedGetter</a></li>
95+
<li><a class="deprecated" href="ex/deprecatedSetter.html">deprecatedSetter</a></li>
9696
<li><a href="ex/number.html">number</a></li>
9797
<li><a href="ex/y.html">y</a></li>
9898

test_package_docs/ex/COLOR-constant.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ <h5><a href="ex/ex-library.html">ex</a></h5>
8484

8585
<li class="section-title"><a href="ex/ex-library.html#properties">Properties</a></li>
8686
<li><a class="deprecated" href="ex/deprecatedField.html">deprecatedField</a></li>
87-
<li><a href="ex/deprecatedGetter.html">deprecatedGetter</a></li>
88-
<li><a href="ex/deprecatedSetter.html">deprecatedSetter</a></li>
87+
<li><a class="deprecated" href="ex/deprecatedGetter.html">deprecatedGetter</a></li>
88+
<li><a class="deprecated" href="ex/deprecatedSetter.html">deprecatedSetter</a></li>
8989
<li><a href="ex/number.html">number</a></li>
9090
<li><a href="ex/y.html">y</a></li>
9191

test_package_docs/ex/COLOR_GREEN-constant.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ <h5><a href="ex/ex-library.html">ex</a></h5>
8484

8585
<li class="section-title"><a href="ex/ex-library.html#properties">Properties</a></li>
8686
<li><a class="deprecated" href="ex/deprecatedField.html">deprecatedField</a></li>
87-
<li><a href="ex/deprecatedGetter.html">deprecatedGetter</a></li>
88-
<li><a href="ex/deprecatedSetter.html">deprecatedSetter</a></li>
87+
<li><a class="deprecated" href="ex/deprecatedGetter.html">deprecatedGetter</a></li>
88+
<li><a class="deprecated" href="ex/deprecatedSetter.html">deprecatedSetter</a></li>
8989
<li><a href="ex/number.html">number</a></li>
9090
<li><a href="ex/y.html">y</a></li>
9191

test_package_docs/ex/COLOR_ORANGE-constant.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ <h5><a href="ex/ex-library.html">ex</a></h5>
8484

8585
<li class="section-title"><a href="ex/ex-library.html#properties">Properties</a></li>
8686
<li><a class="deprecated" href="ex/deprecatedField.html">deprecatedField</a></li>
87-
<li><a href="ex/deprecatedGetter.html">deprecatedGetter</a></li>
88-
<li><a href="ex/deprecatedSetter.html">deprecatedSetter</a></li>
87+
<li><a class="deprecated" href="ex/deprecatedGetter.html">deprecatedGetter</a></li>
88+
<li><a class="deprecated" href="ex/deprecatedSetter.html">deprecatedSetter</a></li>
8989
<li><a href="ex/number.html">number</a></li>
9090
<li><a href="ex/y.html">y</a></li>
9191

test_package_docs/ex/COMPLEX_COLOR-constant.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ <h5><a href="ex/ex-library.html">ex</a></h5>
8484

8585
<li class="section-title"><a href="ex/ex-library.html#properties">Properties</a></li>
8686
<li><a class="deprecated" href="ex/deprecatedField.html">deprecatedField</a></li>
87-
<li><a href="ex/deprecatedGetter.html">deprecatedGetter</a></li>
88-
<li><a href="ex/deprecatedSetter.html">deprecatedSetter</a></li>
87+
<li><a class="deprecated" href="ex/deprecatedGetter.html">deprecatedGetter</a></li>
88+
<li><a class="deprecated" href="ex/deprecatedSetter.html">deprecatedSetter</a></li>
8989
<li><a href="ex/number.html">number</a></li>
9090
<li><a href="ex/y.html">y</a></li>
9191

test_package_docs/ex/Cat-class.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ <h5><a href="ex/ex-library.html">ex</a></h5>
9090

9191
<li class="section-title"><a href="ex/ex-library.html#properties">Properties</a></li>
9292
<li><a class="deprecated" href="ex/deprecatedField.html">deprecatedField</a></li>
93-
<li><a href="ex/deprecatedGetter.html">deprecatedGetter</a></li>
94-
<li><a href="ex/deprecatedSetter.html">deprecatedSetter</a></li>
93+
<li><a class="deprecated" href="ex/deprecatedGetter.html">deprecatedGetter</a></li>
94+
<li><a class="deprecated" href="ex/deprecatedSetter.html">deprecatedSetter</a></li>
9595
<li><a href="ex/number.html">number</a></li>
9696
<li><a href="ex/y.html">y</a></li>
9797

0 commit comments

Comments
 (0)