tom_d4rt_generator library

Tom D4rt Bridge Generator

D4rt bridge generator for creating BridgedClass implementations from Dart source.

This package provides the BridgeGenerator class that analyzes Dart source files and generates corresponding BridgedClass registrations for use with the D4rt interpreter.

Usage

import 'package:tom_d4rt_generator/tom_d4rt_generator.dart';

final generator = BridgeGenerator(
  workspacePath: '/path/to/project',
  packageName: 'my_package',
  sourceImport: 'my_package.dart',
);

final result = await generator.generateBridgesFromExports(
  barrelFiles: ['lib/my_package.dart'],
  outputPath: 'lib/src/d4rt_bridges/my_package_bridges.b.dart',
  moduleName: 'All',
);

Classes

AuxiliaryImport
Information about an auxiliary import needed for types used in defaults/parameters that aren't directly exported from the barrel.
BridgeConfig
Complete bridge configuration for a project.
BridgeFreshness
The outcome of checkBridgeFreshness.
BridgeGenerator
Generates D4rt BridgedClass implementations from Dart source files.
BridgeGeneratorResult
Result of bridge generation.
ClassInfo
Parsed class information for bridge generation.
ConstructorInfo
Information about a constructor.
CorpusTypeScanner
Scans D4rt scripts for the concrete type arguments used in generic instantiations and emits an allowlist consumable by BridgeConfig.additionalRelaxerTypes.
CorpusTypeScanResult
Aggregated result of a corpus scan.
EnumInfo
Information about an enum for bridging.
EnumMethodDetail
RC-7: Detailed information about an enum instance method.
ExportInfo
Information about an export directive from a barrel file.
ExtensionInfo
Information about an extension declaration in the source code.
ExternalTypeDependency
Information about an external type dependency.
ExternalTypeWarning
Warning about external types used in class parameters. These types may need wrapper classes for proper bridge support.
FunctionTypeInfo
Information about a function type signature. Used to generate wrappers for function-type parameters.
GeneratedStamp
A provenance line read back from generated content.
GenerationPreview<T>
The outcome of previewGeneration.
GenerationResult
Result of a bridge generation operation.
GenericConstructorConfig
Configuration for a templated RC-2 generic constructor factory.
GenericCtorNamedArg
One named argument forwarded by a GenericConstructorKind.namedPassthrough generic constructor (e.g. debugLabel of GlobalKey).
GenericExtractionSite
A generic extraction site discovered during bridge code generation.
GenericInterceptorConfig
Declarative spec for a generic method/static interceptor whose adapter drops the script-supplied <T> at the bridge boundary.
GlobalFunctionInfo
Information about a top-level function for bridging.
GlobalVariableInfo
Information about a top-level variable for bridging.
ImportedBridgeConfig
Configuration for an imported bridge package.
MemberInfo
Information about a class member for bridging.
ModuleConfig
Configuration for a single module within a project.
ParameterInfo
Information about a method parameter.
PreviewedWrite
One file a previewed run wrote.
ProxyClassConfig
Configuration for a proxy class to be generated.
ProxyGenerationInfo
Information about a generated proxy class.
ProxyGenerationResult
Result of proxy generation.
RecreatorClassConfig
Configuration for a single-type-parameter widget that must be re-created (rather than relaxer-wrapped) with a script-supplied type argument.
RecursiveBoundType
Configuration for a type to use in recursive bound dispatch.
RelaxerClassConfig
Configuration for a class to include in reduced relaxer/RC-2 generation.
RelaxerGenerationResult
Result of relaxer generation.
RenderBoxProxyVariantSpec
Describes one generated RenderBox-proxy variant: the class name and which variant body/with-clause to emit.
StaleBridge
One generated file whose committed copy does not match a fresh generation.
StateProxyVariantSpec
Describes one generated State-proxy variant: the class name, the optional with mixin clause, and which per-mixin extra overrides to emit.
SuperArgFormal
One super-constructor formal a capture-factory forwards.
TypeArgProxyVariant
A single generic type-argument variant of a ProxyClassConfig.
TypeArgVariantSpec
A single declared type-argument variant: a list of slot templates, one per type parameter of the generic base class.
UserProxyRelaxerScanner
Scans resolved libraries for @D4rtUserProxy / @D4rtUserRelaxer directive classes (those extending the D4UserProxy / D4UserRelaxer marker bases).
UserRelaxerEntry
A discovered user-defined relaxer extension.
UserVariantDirective
A discovered @D4rtUserProxy / @D4rtUserRelaxer directive, with its variant strings parsed into TypeArgVariantSpecs.
WildcardCapture
The $0/$1 capture produced when a WildcardPattern matches a candidate.
WildcardPattern
A parsed single-* wildcard pattern for the driver slot of a variant.

Enums

GenericConstructorKind
Which generated body shape a GenericConstructorConfig templates. The two real shapes in the flutter-material corpus diverge enough that a single template can't cover both without a discriminator.
PreviewedChange
How a previewed write relates to the file already in the package.
RenderBoxProxyVariant
Which RenderBox-proxy variant to emit. Each selects the with clause and the paint / hitTestChildren / setupParentData bodies.
StaleReason
The two ways a committed bridge can disagree with a fresh generation.
StateProxyExtra
The per-mixin extra overrides a State proxy variant must carry on top of the common lifecycle skeleton.
UserVariantKind
Whether a directive drives proxy or relaxer generation.
WildcardMatchKind
How a WildcardPattern matches a candidate class name.

Constants

generatedStampPrefix → const String
What every provenance line starts with.

Functions

applySuperArgDefaults(List<SuperArgFormal> formals, Map<String, String> superArgDefaults) List<SuperArgFormal>
Fill each formal's SuperArgFormal.defaultExpr from superArgDefaults (keyed by formal name) where the formal does not already carry one.
checkBridgeFreshness(String projectPath) Future<BridgeFreshness>
Regenerate projectPath's bridges into a scratch tree and compare them with what the package has committed.
d4rtBridgeBuilder(BuilderOptions options) → Builder
Creates the D4rt bridge builder for build_runner.
ensureBDartExtension(String path) String
Ensures a file path ends with the .b.dart extension.
expandUserVariants(Iterable<TypeArgVariantSpec> specs, Iterable<String> candidates) List<List<String>>
Expand a list of variant specs against a candidate pool, de-duplicating the resulting tuples while preserving first-seen order.
generateBarrelFileContent(BridgeConfig config) String
Generates the content for a barrel file that exports all bridge modules.
generateBridges({BridgeConfig? config, String? configPath, String? projectPath}) Future<GenerationResult>
Generate D4rt bridges for a project.
generateClassChainHasBridgedMixin() String
Emits the _classChainHasBridgedMixin runtime selector free function used by the RenderBox proxy factory to choose between the plain proxy and a container/slotted proxy before instance.nativeProxy is cached.
generateDartscriptFileContent(BridgeConfig config, {String? dartscriptPath, String? packageName}) String
Generates the content for the dartscript registration file.
generatedStampLine({DateTime? at, String? generatorVersion}) String
The provenance line for a file generated now (or at at) by this generator (or by generatorVersion, for tests).
generateGenericConstructor(GenericConstructorConfig config) String
Emits the full D4.registerGenericConstructor(...) statement for config, indented two spaces for emission inside the generated registerGenericConstructors() function.
generateGenericConstructorRegistrations(List<GenericConstructorConfig> configs) String
Emits the _registerGeneratedGenericConstructors() wrapper function with one generateGenericConstructor call per config, in declaration order.
generateGenericInterceptor(GenericInterceptorConfig config) String
Emits the full D4.registerBridged{,Static}MethodInterceptor(...) call for config, including the re-dispatch switch (typeName) over its type-arg allow-list.
generateGenericInterceptorRegistrations(List<GenericInterceptorConfig> configs) String
Emits the _registerGeneratedGenericInterceptors() function wrapping one generateGenericInterceptor call per config, in declaration order.
generateProxies({required BridgeConfig config, required String projectPath, List<String>? librarySummaryPaths, String? sdkSummaryPath, AnalysisContextCollection? analysisContext}) Future<ProxyGenerationResult>
Generates proxy classes for configured abstract delegates.
generateReadSuperArgHelper() String
Emits the shared _readSuperArg<T> helper every capture-factory calls.
generateRelaxers({required BridgeConfig config, required String projectPath, required Map<String, ClassInfo> globalClassLookup, List<GenericExtractionSite> genericExtractionSites = const [], Set<String> gen075Classes = const {}, void onWarning(String)?, Future<void> writeFile(String relativePath, String content)?}) Future<RelaxerGenerationResult>
Generates relaxer wrapper classes and factory functions.
generateRenderBoxProxyFamily(ProxyClassConfig config, {void warn(String message)?}) String
Emits the full RenderBox-proxy family for a RenderBox ProxyClassConfig: the plain variant followed by one variant per recognised name in ProxyClassConfig.mixinVariants, in declaration order, then the _classChainHasBridgedMixin runtime selector helper when any container or slotted variant was emitted (the factory uses it to pick the proxy shape).
generateRenderBoxProxyVariant(RenderBoxProxyVariantSpec spec) String
Emits a single RenderBox-proxy variant class for spec.
generateStateProxyFamily(ProxyClassConfig config, {void warn(String message)?}) String
Emits the full State-proxy family for a State ProxyClassConfig: the plain variant followed by one variant per recognised name in ProxyClassConfig.mixinVariants, in declaration order.
generateStateProxyVariant(StateProxyVariantSpec spec) String
Emits a single State-proxy variant class for spec.
generateSuperArgCaptureFactory({required String baseClassName, required List<SuperArgFormal> formals}) String
Emits the static create(visitor, instance) super-arg-capture factory for a proxy backing interpreted subclasses of baseClassName.
generateSuperArgEntry(SuperArgFormal formal) String
Emits one named-arg entry for the proxy constructor call.
generateTestRunnerContent(BridgeConfig config, {String? testRunnerPath, String? packageName}) String
Generates the content for a test runner script (d4rtrun.b.dart).
generateTypeArgProxyClasses(ProxyClassConfig config) String
Emits the typed proxy-variant classes for config in declaration order.
generateTypeArgProxyFamily(ProxyClassConfig config) String
Convenience: the variant classes followed by a blank line and the selector.
generateTypeArgProxySelector(ProxyClassConfig config) String
Emits the registerInterfaceProxy selector that dispatches to the typed variant matching the script's reified bridged-super type argument.
generateTypeArgProxyVariant(String baseClassName, TypeArgProxyVariant variant) String
Emits one typed proxy-variant class for variant backing interpreted subclasses of $baseClassName<${variant.typeArg}>.
generateWidgetReCreator(String className, ClassInfo info, List<String> innerTypes, Map<String, ClassInfo> globalClassLookup, void warn(String)) String?
Emits a D4.registerGenericTypeWrapper re-creator block for a single type-parameter immutable widget className (recreatorClasses).
mapPrivateSdkLibrary(String uri, {void warnCallback(String)?}) String?
Maps private/internal Dart SDK libraries to their public equivalents.
normaliseGeneratedContent(String content) String
Drop the // Generated: line, the one line that legitimately differs between two generations of identical input — it carries the time, and the generator version.
normalizeLibraryIdentifier(String uri) String
Normalizes a library identifier to its canonical dart: URI where the SDK library is actually sourced from an embedder package.
parseGeneratedStamp(String content) GeneratedStamp?
The provenance line of generated content, or null when it has none.
previewGeneration<T>({required String packageRoot, required Future<T> generate(), String purpose = 'preview'}) Future<GenerationPreview<T>>
Run generate against the package at packageRoot with its *.b.dart writes redirected into a scratch tree, and report every file it wrote, compared with the package's own copy.
renderBoxProxyVariantSpecFor(String mixinName) RenderBoxProxyVariantSpec?
Maps a known bridged RenderBox container-mixin name to its variant spec. Returns null for an unrecognised mixin name (the caller should warn and skip — emitting an arbitrary mixin clause risks an uncompilable proxy).
renderUserVariantInstantiationBlock(Iterable<UserVariantDirective> directives, Iterable<String> candidatePool) String
Renders a deterministic, golden-stable source block listing the concrete generic instantiations a set of directives expands to against a candidatePool.
scanUserRelaxers(String relaxerOutputPath, String projectPath, void warn(String), {String? packageName}) List<UserRelaxerEntry>
Scans for user-defined relaxer files matching *_user_relaxer.dart in the user_relaxers/ subdirectory relative to the relaxer output path.
stateProxyVariantSpecFor(String mixinName) StateProxyVariantSpec?
Maps a known bridged State-mixin name to its variant spec. Returns null for an unrecognised mixin name (the caller should warn and skip — emitting an arbitrary mixin clause risks an uncompilable proxy).
toImportUri(String relativePath) String
Normalizes a relative filesystem path into a POSIX-style Dart import URI.
toPascalCase(String input) String
Converts a snake_case or lowercase string to PascalCase.