File tree 3 files changed +28
-1
lines changed
3 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 3
3
- Document deduplication behavior for the output of
4
4
` GeneratorForAnnotation.generateForAnnotatedElement ` .
5
5
- Support all the glob quotes.
6
- - Require Dart 3.4.0
6
+ - Revive to the object's ` variableElement ` if available
7
7
- Require ` analyzer: ^6.4.0 `
8
+ - Require Dart 3.4.0
8
9
9
10
## 1.5.0
10
11
Original file line number Diff line number Diff line change @@ -20,6 +20,21 @@ import '../utils.dart';
20
20
/// Dart source code (such as referencing private constructors). It is up to the
21
21
/// build tool(s) using this library to surface error messages to the user.
22
22
Revivable reviveInstance (DartObject object, [LibraryElement ? origin]) {
23
+ final variableElement = object.variable;
24
+ if (variableElement != null &&
25
+ variableElement.isConst &&
26
+ variableElement.isPublic) {
27
+ final url = Uri .parse (urlOfElement (variableElement)).removeFragment ();
28
+ if (variableElement.enclosingElement
29
+ case final TypeDefiningElement enclosingElement? ) {
30
+ return Revivable ._(
31
+ source: url,
32
+ accessor: '${enclosingElement .name }.${variableElement .name }' ,
33
+ );
34
+ }
35
+ return Revivable ._(source: url, accessor: variableElement.name);
36
+ }
37
+
23
38
final objectType = object.type;
24
39
Element ? element = objectType! .alias? .element;
25
40
if (element == null ) {
Original file line number Diff line number Diff line change @@ -227,6 +227,7 @@ void main() {
227
227
@_privateField
228
228
@Wrapper(_privateFunction)
229
229
@ProcessStartMode.normal
230
+ @ExtensionTypeWithStaticField.staticField
230
231
class Example {}
231
232
232
233
class Int64Like implements Int64LikeBase{
@@ -296,6 +297,10 @@ void main() {
296
297
}
297
298
298
299
void _privateFunction() {}
300
+
301
+ extension type const ExtensionTypeWithStaticField._(int _) {
302
+ static const staticField = ExtensionTypeWithStaticField._(1);
303
+ }
299
304
''' ,
300
305
(resolver) async => (await resolver.findLibraryByName ('test_lib' ))! ,
301
306
);
@@ -393,5 +398,11 @@ void main() {
393
398
expect (staticFieldWithPrivateImpl.isPrivate, isFalse);
394
399
expect (staticFieldWithPrivateImpl.source.fragment, isEmpty);
395
400
});
401
+
402
+ test ('should decode static fields on extension types' , () {
403
+ final fieldOnly = constants[14 ].revive ();
404
+ expect (fieldOnly.source.fragment, isEmpty);
405
+ expect (fieldOnly.accessor, 'ExtensionTypeWithStaticField.staticField' );
406
+ });
396
407
});
397
408
}
You can’t perform that action at this time.
0 commit comments