You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With the upcoming record_use feature, users can record usage of certain Dart objects by placing @RecordUse annotations on the objects. To retrieve the recordings, they need to provide the identifier of the object, a 3-tuple of URI, parent class, and name. This is a source of errors, as typos can be made, and the identifiers have to be updated whenever the annotations are placed elsewhere.
To alleviate this, we could auto-generate the IDs, for example using macros. Example:
//in lib/src/myfile.dartclassMyClass {
@RecordUsestaticboolisPositive(int i) => i >0;
}
@RecordUseclassMyAnnotation {
constMyAnnotation();
}
//in lib/src/ids.g.dartconstMyClass_isPositive_ID=Identifier(
uri:'package:mypackage/lib/src/myfile.dart',
parent:'MyClass',
name:'isPositive',
);
constMyAnnotation_ID=Identifier(
uri:'package:mypackage/lib/src/myfile.dart',
name:'MyAnnotation',
);
//in hook/link.dartimport'../lib/src/ids.g.dart';
voidmain(List<String> arguments){
link(arguments, (config, output) async {
final uses = config.recordedUses;
final args = uses.constArgumentsTo(MyClass_isPositive_ID));
final fields = uses.instanceReferencesTo(MyAnnotation_ID);
... // Do something with the information, such as tree-shaking native assets
});
}
With the upcoming
record_use
feature, users can record usage of certain Dart objects by placing@RecordUse
annotations on the objects. To retrieve the recordings, they need to provide the identifier of the object, a 3-tuple of URI, parent class, and name. This is a source of errors, as typos can be made, and the identifiers have to be updated whenever the annotations are placed elsewhere.To alleviate this, we could auto-generate the IDs, for example using macros. Example:
cc @dcharkes @mkustermann @jakemac53
The text was updated successfully, but these errors were encountered: