Files
sdk/pkg/vm/testcases/transformations/resource_identifier/complex.dart
T
Moritz a3568286ff Adding the resource-identifier functionality from the compiler to the
vm.

This identifies all calls to static methods annotated with
`@ResourceIdentifier`, collects the constant arguments passed to the
method, and writes the results into a file.

The purpose of this feature is to be able to pass the recorded
information to packages in a post-compilation step, allowing them to
remove or modify assets based on the actual usage in the code prior to
bundling in the final application.

Tested: pkg/vm/test/transformations/resource_identifier_test.dart
Change-Id: I58cb313b66ee23c1d154dcc242547723a1ced359
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/329961
Commit-Queue: Moritz Sümmermann <mosum@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
2023-11-21 15:05:35 +00:00

53 lines
1.3 KiB
Dart

// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'package:meta/meta.dart' show ResourceIdentifier;
void main() {
print(OtherClass().someMethod(argument: 'argument!'));
}
class OtherClass {
final AssetBundle bundle = AssetBundle();
String string = 'somestring';
AnotherClass object = AnotherClass();
Future<String> someMethod({required String argument}) async {
return await generate(
bundle,
[argument],
string,
object,
42,
);
}
@ResourceIdentifier('myresourceid')
static Future<String> generate(AssetBundle bundle, List args, String string,
AnotherClass object, int index) async {
final message = await bundle.byIndex(string: string, index: index);
return message.generateString(args, object: object);
}
}
class AssetBundle {
Message byIndex({required String string, required int index}) {
return Message();
}
}
class Message {
Future<String> generateString(List args,
{required AnotherClass object}) async {
return args.firstOrNull.toString();
}
}
class SomeClass {}
class AnotherClass {}