← Reflection
Publishedrole: extensionlicense: BSD-3-Clause

tom_reflection_generator

tom_reflection_generator · v1.1.1

The standalone generator that produces the `.reflection.dart` files `tom_reflection` consumes. It runs as a build_runner builder or a CLI for one-off and CI builds.

View repository → See License
Status
Published
LOC
7.0k
Tests
4
Test LOC
46

Overview

`tom_reflection_generator` builds the reflection data that `tom_reflection` depends on. It scans annotated Dart sources and emits the `.reflection.dart` files that carry the mirror information for runtime introspection and invocation. It can run two ways: as a `build_runner` builder wired through `build.yaml`, or as a standalone command-line tool for single entry points, recursive directory processing, or CI pipelines. A programmatic API is also exposed for embedding generation in other tools. The package bundles the builder, the build_runner integration, and the CLI that were previously part of the Tom build tooling, so any Dart or Flutter workspace using `tom_reflection` can generate reflection without that heavier dependency.

What it enables

Enables Reflection data generation, build_runner integration, CLI and CI builds.

Relationships

Standalone — no declared relationships.

Tom Reflection Generator

`tom_reflection_generator` bundles the Tom reflection builder, a `build_runner` integration, and the standalone CLI that was previously part of `tom_build_tools`. The package can be published to pub.dev and consumed by any Dart or Flutter workspace that needs to generate `.reflection.dart` files for projects using `tom_reflection`.

Features

  • `builder`: `ReflectionGenerator` with build.yaml wiring for build_runner
  • `CLI`: `dart run tom_reflection_generator [...]` for one-off or CI builds
  • Shared analyzer infrastructure (`StandaloneLibraryResolver`, `FileId`, etc.)
  • Matches the behavior of the original tooling from `tom_build`/`tom_build_tools`

Installing

Add the dependency:

dependencies:
  tom_reflection_generator: ^1.0.0

build_runner configuration

targets:
  $default:
    builders:
      tom_reflection_generator|reflection_generator:
        generate_for:
          - lib/**/*.dart

Standalone CLI

# Generate for a single entry point
dart run tom_reflection_generator lib/main.dart

# Generate recursively (use --all to treat directories as recursive)
dart run tom_reflection_generator --all lib/

# Use build mode with build.yaml
dart run tom_reflection_generator build

# Provide explicit glob patterns
dart run tom_reflection_generator build "lib/**/*.dart" "test/**_test.dart"

Key CLI flags:

FlagDescription
`--all`Recursively process a directory
`--package`, `-p`Override reflection package name (default `tom_reflection`)
`--extension`, `-e` Change the generated file extension (default `.reflection.dart`)
`--config`, `-c`Custom config when running in `build` mode
`--useAllCapabilities`Ignore reflector capabilities and emit full metadata
`--verbose`, `-v`Verbose logging

Programmatic usage

import 'package:tom_reflection_generator/tom_reflection_generator.dart';

Future<void> main() async {
  final resolver = await StandaloneLibraryResolver.create('path/to/project');

  final generator = GeneratorImplementation();
  final inputId = FileId('my_package', 'lib/main.dart');
  final outputId = inputId.changeExtension('.reflection.dart');
  final library = await resolver.libraryFor(inputId);
  final visibleLibraries = await resolver.libraries;

  final source = await generator.buildMirrorLibrary(
    resolver,
    inputId,
    outputId,
    library,
    visibleLibraries.cast(),
    true,
    const [],
  );

  // Write the generated source somewhere meaningful.
}

Documentation

  • [Reflection Generator Usage](doc/reflection_generator.md)
  • [Reflection Generator Implementation](doc/reflection_generator_implementation.md)
  • [Tom Reflection Test Status](doc/reflection_test_result.md)

License

BSD-style license, consistent with the rest of the Tom workspace.

License
Copyright (c) 2015, Dart
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
  list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.

* Neither the name of reflectable nor the names of its
  contributors may be used to endorse or promote products derived from
  this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Refactoring, modifications and enhancements (c) 2026, Peter Nicolai Alexis Kyaw