Skip to content

Commit 0ff12d3

Browse files
stereotype441Commit Queue
authored andcommitted
[analyzer] Fix handling of annotated vars/fields in api.txt.
Changes the tool that generates `api.txt` files for the analyzer (and related packages) so that when examining a synthetic element, it looks for annotations on the corresponding non-synthetic element. This fixes detection of `@deprecated` and `@experimental` on getters and setters induced by top level variables and fields. Addresses https://dart-review.googlesource.com/c/sdk/+/455820/comment/f2a39140_563a86de/. Change-Id: I6a6a6964c06905fc94b27a48a150cb2430afad99 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/456320 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent a46b4bb commit 0ff12d3

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

pkg/analyzer/api.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,8 @@ package:analyzer/dart/analysis/utilities.dart:
578578
parseString (function: ParseStringResult Function({required String content, FeatureSet? featureSet, String? path, bool throwIfDiagnostics}))
579579
resolveFile (function: Future<SomeResolvedUnitResult> Function({required String path, ResourceProvider? resourceProvider}))
580580
package:analyzer/dart/ast/ast.dart:
581-
useDeclaringConstructorsAst (static getter: bool)
582-
useDeclaringConstructorsAst= (static setter: bool)
581+
useDeclaringConstructorsAst (static getter: bool, experimental)
582+
useDeclaringConstructorsAst= (static setter: bool, experimental)
583583
AdjacentStrings (class extends Object implements StringLiteral):
584584
strings (getter: NodeList<StringLiteral>)
585585
AnnotatedNode (class extends Object implements AstNode):

pkg/analyzer_utilities/lib/tool/api.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,14 @@ class ApiDescription {
402402
throw UnimplementedError('Unexpected element: $runtimeType');
403403
}
404404

405-
if (element.metadata.hasDeprecated) {
405+
// For synthetic elements such as getters/setters induced by top level
406+
// variables and fields, annotations can be found on the corresponding
407+
// non-synthetic element.
408+
var nonSyntheticElement = element.nonSynthetic;
409+
if (nonSyntheticElement.metadata.hasDeprecated) {
406410
parentheticals.add(['deprecated']);
407411
}
408-
if (element.metadata.hasExperimental) {
412+
if (nonSyntheticElement.metadata.hasExperimental) {
409413
parentheticals.add(['experimental']);
410414
}
411415

0 commit comments

Comments
 (0)