MockLibraryGenerator constructor

MockLibraryGenerator({
  1. required MirrorSystem mirrorSystem,
  2. required List<LibraryMirror> forceLoadedMirrors,
  3. required void onInfo(
    1. String
    ),
  4. required void onWarning(
    1. String
    ),
  5. required void onError(
    1. String
    ),
  6. required RuntimeScannerConfiguration configuration,
  7. required List<Package> packages,
})

A mock implementation of LibraryGenerator that generates reflection metadata using Dart's mirrors API without filesystem operations.

This generator is designed for testing and development scenarios where:

  • Full reflection is needed but without filesystem access
  • Only specific libraries need to be processed
  • Simplified package resolution is acceptable

Key Differences from LibraryGenerator

  • Operates only on in-memory mirror data
  • Doesn't perform filesystem scanning
  • Uses simplified package resolution
  • Processes only current isolate and force-loaded mirrors

Example Usage

final generator = MockLibraryGenerator(
  mirrorSystem: currentMirrorSystem(),
  forceLoadedMirrors: [reflectClass(MyClass)!.owner as LibraryMirror],
  onInfo: (msg) => logger.info(msg),
  onError: (err) => logger.error(err),
  configuration: RuntimeScanLoader(
    scanClasses: [MyClass, MyOtherClass],
  ),
  packages: [
    Package(name: 'my_pkg', version: '1.0.0'),
  ],
);

final libraries = await generator.generate();

Creates a mock library generator with direct mirror system access.

Parameters:

  • mirrorSystem: The mirror system to use for reflection
  • forceLoadedMirrors: Additional libraries to process beyond current isolate
  • onInfo: Callback for informational messages
  • onError: Callback for error messages
  • configuration: Configuration for the scanning process
  • packages: Known package metadata

All parameters are required and non-nullable.

Implementation

MockLibraryGenerator({
  required super.mirrorSystem,
  required super.forceLoadedMirrors,
  required super.onInfo,
  required super.onWarning,
  required super.onError,
  required super.configuration,
  required super.packages,
});