MockRuntimeScanner constructor

MockRuntimeScanner({
  1. OnLogged? onInfo,
  2. OnLogged? onWarning,
  3. OnLogged? onError,
  4. List<File> forceLoadFiles = const [],
  5. MockLibraryGeneratorFactory? libraryGeneratorFactory,
  6. bool includeCurrentIsolateLibraries = true,
})

A lightweight mock implementation of RuntimeScanner for testing and development.

This scanner provides a simplified reflection system that:

  • Operates only on the current isolate's libraries
  • Supports force-loading specific files
  • Uses Dart's mirrors API instead of filesystem scanning
  • Provides configurable logging
  • Allows custom library generator injection

{@template mock_runtime_scan_features}

Key Features

  • Isolated Scanning: Only processes currently loaded libraries by default
  • Selective Loading: Can force-load specific files via forceLoadFiles
  • Pluggable Logging: Configurable info/warning/error callbacks
  • Custom Generators: Supports alternative library generators via factory
  • Primitive Type Support: Automatically includes Dart core types

When to Use

  • Unit testing reflection-dependent code
  • Development environments where full scanning is unnecessary
  • CI pipelines requiring lightweight reflection
  • Debugging specific library reflection

Creates a mock runtime scanner with configurable behavior.

Parameters:

  • onInfo: Optional callback for informational messages
  • onWarning: Optional callback for warning messages
  • onError: Optional callback for error messages
  • forceLoadFiles: Additional files to load for scanning (default empty)
  • libraryGeneratorFactory: Custom generator factory (defaults to MockLibraryGenerator)
  • includeCurrentIsolateLibraries: Whether to scan current isolate (default true)

Example:

final mockScan = MockRuntimeScan(
  onError: (err) => Sentry.captureException(err),
  forceLoadFiles: criticalFiles,
);

Implementation

MockRuntimeScanner({
  OnLogged? onInfo,
  OnLogged? onWarning,
  OnLogged? onError,
  List<File> forceLoadFiles = const [],
  MockLibraryGeneratorFactory? libraryGeneratorFactory,
  bool includeCurrentIsolateLibraries = true,
}) : _onInfo = onInfo,
     _onWarning = onWarning,
     _onError = onError,
     _forceLoadFiles = forceLoadFiles,
     _libraryGeneratorFactory = libraryGeneratorFactory;