MockLibraryGenerator class
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
-
- Object
- LibraryGenerator
- ApplicationLibraryGenerator
- MockLibraryGenerator
Constructors
-
MockLibraryGenerator({required MirrorSystem mirrorSystem, required List<
LibraryMirror> forceLoadedMirrors, required void onInfo(String), required void onWarning(String), required void onError(String), 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
-
loader
→ List<
LibraryMirror> -
no setterinherited
- mirrorSystem → MirrorSystem
-
The mirror system used for reflection
finalinherited
- onError → void Function(String)
-
Callback for error messages
finalinherited
- onInfo → void Function(String)
-
Callback for informational messages
finalinherited
- onWarning → void Function(String)
-
Callback for warning messages
finalinherited
-
packages
→ List<
Package> -
List of packages to process
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
generate(
List< File> dartFiles) → Future<List< LibraryDeclaration> > -
Generates both reflection metadata and concrete reflector classes.
inherited
-
generateClass(
ClassMirror classMirror, Package package, String libraryUri, Uri sourceUri) → Future< ClassDeclaration> -
Generate class declaration with integrated analyzer support
inherited
-
generateConstructor(
MethodMirror constructorMirror, Element? parentElement, Package package, String libraryUri, Uri sourceUri, String className, ClassDeclaration parentClass) → Future< ConstructorDeclaration> -
Generate constructor declaration with analyzer support
inherited
-
generateEnum(
ClassMirror enumMirror, Package package, String libraryUri, Uri sourceUri) → Future< EnumDeclaration> -
Generate enum declaration with analyzer support
inherited
-
generateField(
VariableMirror fieldMirror, Element? parentElement, Package package, String libraryUri, Uri sourceUri, String className, ClassDeclaration? parentClass, String? sourceCode) → Future< FieldDeclaration> -
Generate field declaration with analyzer support
inherited
-
generateLibrary(
LibraryMirror libraryMirror) → Future< LibraryDeclaration> -
Generate library declaration with integrated analyzer support
inherited
-
generateMethod(
MethodMirror methodMirror, Element? parentElement, Package package, String libraryUri, Uri sourceUri, String className, ClassDeclaration? parentClass) → Future< MethodDeclaration> -
Generate method declaration with analyzer support
inherited
-
generateMixin(
ClassMirror mixinMirror, Package package, String libraryUri, Uri sourceUri) → Future< MixinDeclaration> -
Generate mixin declaration with analyzer support
inherited
-
generateTopLevelField(
VariableMirror fieldMirror, Package package, String libraryUri, Uri sourceUri) → Future< FieldDeclaration> -
Generate top-level field with analyzer support
inherited
-
generateTopLevelMethod(
MethodMirror methodMirror, Package package, String libraryUri, Uri sourceUri) → Future< MethodDeclaration> -
Generate top-level method with analyzer support
inherited
-
generateType(
TypeMirror typeMirror, Package package, String libraryUri) → Future< TypeDeclaration> -
Generate type declaration with analyzer support
inherited
-
generateTypedef(
TypedefMirror typedefMirror, Package package, String libraryUri, Uri sourceUri) → Future< TypedefDeclaration> -
Generate typedef declaration with analyzer support
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
-
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