Skip to content

Commit 931fbb3

Browse files
pqCommit Queue
authored andcommitted
[element model] migrate metadata_test
Change-Id: I29c0c6c71b04d5fb81990f97b68727a786c12022 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/400220 Reviewed-by: Brian Wilkerson <[email protected]> Auto-Submit: Phil Quitslund <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent 3bbcf1b commit 931fbb3

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

pkg/analyzer/analyzer_use_new_elements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ test/src/dart/resolution/constant_test.dart
211211
test/src/dart/resolution/context_collection_resolution.dart
212212
test/src/dart/resolution/generic_type_alias_test.dart
213213
test/src/dart/resolution/local_variable_test.dart
214-
test/src/dart/resolution/metadata_test.dart
215214
test/src/dart/resolution/prefix_element_test.dart
216215
test/src/dart/resolution/resolution.dart
217216
test/src/dart/resolution/scope_test.dart

pkg/analyzer/lib/dart/element/element2.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1807,7 +1807,7 @@ abstract class LocalFunctionFragment
18071807
///
18081808
/// Clients may not extend, implement or mix-in this class.
18091809
abstract class LocalVariableElement2
1810-
implements PromotableElement2, LocalElement2 {
1810+
implements PromotableElement2, LocalElement2, Annotatable {
18111811
@override
18121812
LocalVariableElement2 get baseElement;
18131813

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7410,6 +7410,9 @@ class LocalVariableElementImpl2 extends PromotableElementImpl2
74107410
@override
74117411
LocalVariableElement2 get baseElement => this;
74127412

7413+
@override
7414+
String? get documentationComment => null;
7415+
74137416
@override
74147417
LocalVariableFragment get firstFragment => _wrappedElement;
74157418

@@ -7436,6 +7439,9 @@ class LocalVariableElementImpl2 extends PromotableElementImpl2
74367439
return _wrappedElement.library2;
74377440
}
74387441

7442+
@override
7443+
Metadata get metadata2 => wrappedElement.metadata2;
7444+
74397445
@override
74407446
DartType get type => _wrappedElement.type;
74417447

pkg/analyzer/test/src/dart/resolution/metadata_test.dart

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:analyzer/dart/ast/ast.dart';
6-
import 'package:analyzer/dart/element/element.dart';
6+
import 'package:analyzer/dart/element/element2.dart';
77
import 'package:analyzer/src/error/codes.dart';
88
import 'package:analyzer/src/test_utilities/find_element.dart';
99
import 'package:test_reflective_loader/test_reflective_loader.dart';
@@ -267,8 +267,8 @@ Annotation
267267
element2: <testLibraryFragment>::@class::A::@constructor::new#element
268268
''');
269269

270-
var localVariable = findElement.localVar('x');
271-
var annotationOnElement = localVariable.metadata.single;
270+
var localVariable = findElement2.localVar('x');
271+
var annotationOnElement = localVariable.firstAnnotation;
272272
_assertElementAnnotationValueText(annotationOnElement, '''
273273
A
274274
a: int 3
@@ -1485,8 +1485,8 @@ import 'a.dart';
14851485
void f(C c) {}
14861486
''');
14871487

1488-
var classC = findNode.namedType('C c').element!;
1489-
var annotation = classC.metadata.single;
1488+
var classC = findNode.namedType('C c').element2!;
1489+
var annotation = classC.firstAnnotation;
14901490
_assertElementAnnotationValueText(annotation, r'''
14911491
B
14921492
a: A
@@ -1515,8 +1515,8 @@ import 'b.dart';
15151515
void f(B b) {}
15161516
''');
15171517

1518-
var classB = findNode.namedType('B b').element!;
1519-
var annotation = classB.metadata.single;
1518+
var classB = findNode.namedType('B b').element2!;
1519+
var annotation = classB.firstAnnotation;
15201520
_assertElementAnnotationValueText(annotation, r'''
15211521
A
15221522
f: int 42
@@ -1544,8 +1544,8 @@ import 'b.dart';
15441544
void f(B b) {}
15451545
''');
15461546

1547-
var classB = findNode.namedType('B b').element!;
1548-
var annotation = classB.metadata.single;
1547+
var classB = findNode.namedType('B b').element2!;
1548+
var annotation = classB.firstAnnotation;
15491549
_assertElementAnnotationValueText(annotation, r'''
15501550
A
15511551
f: int 42
@@ -2671,3 +2671,8 @@ int 42
26712671
assertDartObjectText(value, expected);
26722672
}
26732673
}
2674+
2675+
extension on Element2 {
2676+
ElementAnnotation get firstAnnotation =>
2677+
(this as Annotatable).metadata2.annotations.first;
2678+
}

0 commit comments

Comments
 (0)