MockLibraryGenerator class base

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();
Inheritance

Constructors

MockLibraryGenerator({required MirrorSystem mirrorSystem, required List<LibraryMirror> forceLoadedMirrors, required RuntimeScannerConfiguration configuration, required List<Package> packages})
A mock implementation of LibraryGenerator that generates reflection metadata using Dart's mirrors API without filesystem operations.

Properties

configuration RuntimeScannerConfiguration
The runtime scan loader configuration
finalinherited
forceLoadedMirrors List<LibraryMirror>
List of mirrors that should be force-loaded
finalinherited
hashCode int
The hash code for this object.
no setterinherited
mirrorSystem MirrorSystem
The mirror system used for reflection
finalinherited
packageCache Map<String, Package>
Cache storing resolved Package metadata keyed by package name.
finalinherited
packages List<Package>
List of packages to process
finalinherited
refresh bool
Whether the library list should be refreshed using the full set of mirrors provided by the VM.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

generate(List<File> dartFiles) Future<void>
Generates both reflection metadata and concrete reflector classes.
inherited
generateLibrary(LibraryMirror library) Future<void>
Generates runtime metadata for a single Dart library.
inherited
getLibraries() List<LibraryMirror>
List of library mirrors to process
inherited
getPackageNameFromUri(dynamic uri) String?
Parameters:
inherited
hasMirrorImport(String content) bool
inherited
isNonLoadableJetLeafFile(Uri uri) bool
Checks if the file matches any of the excluded JetLeaf internal paths.
inherited
isPartOf(String content) bool
Parameters:
inherited
isSkippableJetLeafPackage(Uri identifier) bool
Checks if the file matches any of the excluded JetLeaf internal paths.
inherited
isTest(String content) bool
Checks if content is a test file.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
readSourceCode(Object uri) Future<String>
Reads and returns the normalized source code for a Dart library.
inherited
resolveUri(Uri uri) Future<Uri?>
Parameters:
inherited
shouldNotIncludeLibrary(Uri uri, RuntimeScannerConfiguration configuration) Future<bool>
Parameters:
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited