├── .gitattributes
├── .github
├── dependabot.yaml
└── workflows
│ └── dart.yml
├── .gitignore
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── goldens
├── README.md
└── foo
│ ├── analysis_options.yaml
│ ├── lib
│ ├── built_value
│ │ ├── built_value_test.analyzer.augmentations
│ │ └── built_value_test.dart
│ ├── declare_x.analyzer.augmentations
│ ├── declare_x.cfe.augmentations
│ ├── declare_x.dart
│ ├── foo.analyzer.json
│ ├── foo.cfe.json
│ ├── foo.dart
│ ├── json_codable_test.analyzer.augmentations
│ ├── json_codable_test.dart
│ ├── literal_params.analyzer.augmentations
│ ├── literal_params.dart
│ ├── metadata.analyzer.json
│ └── metadata.dart
│ ├── mono_pkg.yaml
│ └── pubspec.yaml
├── mono_repo.yaml
├── pkgs
├── _analyzer_cfe_macros
│ ├── analysis_options.yaml
│ ├── lib
│ │ └── metadata_converter.dart
│ ├── mono_pkg.yaml
│ ├── pubspec.yaml
│ └── test
│ │ └── metadata_converter_test.dart
├── _analyzer_macros
│ ├── analysis_options.yaml
│ ├── bin
│ │ └── server.dart
│ ├── lib
│ │ ├── macro_implementation.dart
│ │ ├── query_service.dart
│ │ └── src
│ │ │ └── type_translation.dart
│ ├── mono_pkg.yaml
│ ├── pubspec.yaml
│ └── test
│ │ ├── analyzer_test.dart
│ │ ├── golden_test.dart
│ │ └── package_under_test
│ │ ├── analysis_options.yaml
│ │ ├── lib
│ │ ├── apply_declare_x.dart
│ │ └── apply_query_class.dart
│ │ └── pubspec.yaml
├── _cfe_macros
│ ├── analysis_options.yaml
│ ├── lib
│ │ ├── macro_implementation.dart
│ │ ├── query_service.dart
│ │ └── src
│ │ │ └── type_translation.dart
│ ├── mono_pkg.yaml
│ ├── pubspec.yaml
│ └── test
│ │ ├── cfe_test.dart
│ │ ├── golden_test.dart
│ │ └── package_under_test
│ │ ├── analysis_options.yaml
│ │ ├── lib
│ │ ├── apply_declare_x.dart
│ │ └── apply_query_class.dart
│ │ └── pubspec.yaml
├── _macro_builder
│ ├── analysis_options.yaml
│ ├── lib
│ │ ├── macro_builder.dart
│ │ └── src
│ │ │ └── bootstrap.dart
│ ├── mono_pkg.yaml
│ ├── pubspec.yaml
│ └── test
│ │ └── macro_builder_test.dart
├── _macro_client
│ ├── analysis_options.yaml
│ ├── lib
│ │ ├── macro_client.dart
│ │ └── src
│ │ │ ├── builder_impls.dart
│ │ │ └── execute_macro.dart
│ ├── mono_pkg.yaml
│ ├── pubspec.yaml
│ └── test
│ │ └── macro_client_test.dart
├── _macro_host
│ ├── analysis_options.yaml
│ ├── lib
│ │ ├── macro_host.dart
│ │ └── src
│ │ │ ├── macro_cache.dart
│ │ │ ├── macro_host.dart
│ │ │ └── package_config.dart
│ ├── mono_pkg.yaml
│ ├── pubspec.yaml
│ └── test
│ │ ├── macro_host_test.dart
│ │ └── package_config_test.dart
├── _macro_runner
│ ├── analysis_options.yaml
│ ├── lib
│ │ └── macro_runner.dart
│ ├── mono_pkg.yaml
│ ├── pubspec.yaml
│ └── test
│ │ └── macro_runner_test.dart
├── _macro_server
│ ├── analysis_options.yaml
│ ├── lib
│ │ └── macro_server.dart
│ ├── mono_pkg.yaml
│ ├── pubspec.yaml
│ └── test
│ │ └── macro_server_test.dart
├── _macro_tool
│ ├── README.md
│ ├── bin
│ │ └── _macro_tool.dart
│ ├── lib
│ │ ├── analyzer_macro_runner.dart
│ │ ├── cfe_macro_runner.dart
│ │ ├── macro_runner.dart
│ │ ├── macro_tool.dart
│ │ ├── main.dart
│ │ └── source_file.dart
│ ├── mono_pkg.yaml
│ ├── pubspec.yaml
│ └── test
│ │ ├── macro_runner_test.dart
│ │ ├── macro_tool_test.dart
│ │ └── package_under_test
│ │ ├── analysis_options.yaml
│ │ ├── lib
│ │ ├── apply_declare_x.dart
│ │ └── apply_query_class.dart
│ │ └── pubspec.yaml
├── _test_macros
│ ├── analysis_options.yaml
│ ├── lib
│ │ ├── built_value.dart
│ │ ├── declare_x_macro.dart
│ │ ├── json_codable.dart
│ │ ├── literal_params.dart
│ │ ├── query_class.dart
│ │ └── templating.dart
│ ├── mono_pkg.yaml
│ └── pubspec.yaml
├── dart_model
│ ├── README.md
│ ├── analysis_options.yaml
│ ├── benchmark
│ │ ├── builder_maps_builder_wire_benchmark.dart
│ │ ├── builder_maps_json_wire_benchmark.dart
│ │ ├── json_buffer.dart
│ │ ├── lazy_maps_buffer_wire_benchmark.dart
│ │ ├── lazy_maps_json_wire_benchmark.dart
│ │ ├── lazy_wrappers_buffer_wire_benchmark.dart
│ │ ├── main.dart
│ │ ├── regular_dart_classes.dart
│ │ ├── sdk_maps_buffer_wire_benchmark.dart
│ │ ├── sdk_maps_builder_wire_benchmark.dart
│ │ ├── sdk_maps_json_wire_benchmark.dart
│ │ └── serialization_benchmark.dart
│ ├── lib
│ │ ├── dart_model.dart
│ │ ├── serialization.dart
│ │ └── src
│ │ │ ├── dart_model.dart
│ │ │ ├── dart_model.g.dart
│ │ │ ├── deep_cast_map.dart
│ │ │ ├── json_buffer
│ │ │ ├── closed_list.dart
│ │ │ ├── closed_map.dart
│ │ │ ├── explanations.dart
│ │ │ ├── growable_map.dart
│ │ │ ├── iterables.dart
│ │ │ ├── json_buffer_builder.dart
│ │ │ ├── type.dart
│ │ │ └── typed_map.dart
│ │ │ ├── lazy_merged_map.dart
│ │ │ ├── macro_metadata.g.dart
│ │ │ ├── scopes.dart
│ │ │ ├── type.dart
│ │ │ └── type_system.dart
│ ├── mono_pkg.yaml
│ ├── pubspec.yaml
│ └── test
│ │ ├── deep_cast_test.dart
│ │ ├── json_buffer
│ │ ├── closed_list_test.dart
│ │ ├── closed_map_test.dart
│ │ ├── growable_map_test.dart
│ │ ├── json_buffer_builder_test.dart
│ │ ├── testing.dart
│ │ └── typed_map_test.dart
│ │ ├── lazy_merged_map_test.dart
│ │ ├── model_test.dart
│ │ ├── scopes_test.dart
│ │ ├── type_system_test.dart
│ │ └── type_test.dart
├── macro
│ ├── analysis_options.yaml
│ ├── lib
│ │ ├── macro.dart
│ │ └── src
│ │ │ ├── builders.dart
│ │ │ └── macro.dart
│ ├── mono_pkg.yaml
│ └── pubspec.yaml
└── macro_service
│ ├── analysis_options.yaml
│ ├── lib
│ ├── macro_service.dart
│ └── src
│ │ ├── handshake.g.dart
│ │ ├── macro_service.dart
│ │ ├── macro_service.g.dart
│ │ └── message_grouper.dart
│ ├── mono_pkg.yaml
│ ├── pubspec.yaml
│ └── test
│ └── protocol_test.dart
├── pubspec.yaml
├── schemas
├── dart_model.schema.json
├── handshake.schema.json
├── macro_metadata.schema.json
└── macro_service.schema.json
└── tool
├── benchmark_generator
├── README.md
├── bin
│ └── benchmark_generator.dart
├── lib
│ ├── input_generator.dart
│ └── workspace.dart
├── mono_pkg.yaml
└── pubspec.yaml
├── ci.sh
├── dart_model_generator
├── analysis_options.yaml
├── bin
│ └── main.dart
├── lib
│ ├── definitions.dart
│ ├── generate_dart_model.dart
│ └── macro_metadata_definitions.dart
├── mono_pkg.yaml
├── pubspec.yaml
└── test
│ └── generated_output_test.dart
├── generate_converter
├── generate_definitions
├── run_e2e_tests.sh
└── set_sdk_ref
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Stop git from changing golden file line endings on checkout.
2 | *.augmentations binary
3 | *.json binary
4 |
--------------------------------------------------------------------------------
/.github/dependabot.yaml:
--------------------------------------------------------------------------------
1 | # Dependabot configuration file.
2 | version: 2
3 |
4 | updates:
5 | - package-ecosystem: github-actions
6 | directory: /
7 | schedule:
8 | interval: monthly
9 | labels:
10 | - autosubmit
11 | groups:
12 | github-actions:
13 | patterns:
14 | - "*"
15 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | **/.dart_tool
2 | **/pubspec.lock
3 | goldens/foo/lib/generated/**
4 | *.macro_tool_output
5 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to Contribute
2 |
3 | We'd love to accept your patches and contributions to this project. There are
4 | just a few small guidelines you need to follow.
5 |
6 | ## Contributor License Agreement
7 |
8 | Contributions to this project must be accompanied by a Contributor License
9 | Agreement (CLA). You (or your employer) retain the copyright to your
10 | contribution; this simply gives us permission to use and redistribute your
11 | contributions as part of the project. Head over to
12 | to see your current agreements on file or
13 | to sign a new one.
14 |
15 | You generally only need to submit a CLA once, so if you've already submitted one
16 | (even if it was for a different project), you probably don't need to do it
17 | again.
18 |
19 | ## Code Reviews
20 |
21 | All submissions, including submissions by project members, require review. We
22 | use GitHub pull requests for this purpose. Consult
23 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
24 | information on using pull requests.
25 |
26 | ## Coding style
27 |
28 | The Dart source code in this repo follows the:
29 |
30 | * [Dart style guide](https://dart.dev/guides/language/effective-dart/style)
31 |
32 | You should familiarize yourself with those guidelines.
33 |
34 | ## File headers
35 |
36 | All files in the Dart project must start with the following header; if you add a
37 | new file please also add this. The year should be a single number stating the
38 | year the file was created (don't use a range like "2011-2012"). Additionally, if
39 | you edit an existing file, you shouldn't update the year.
40 |
41 | // Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
42 | // for details. All rights reserved. Use of this source code is governed by a
43 | // BSD-style license that can be found in the LICENSE file.
44 |
45 | ## Community Guidelines
46 |
47 | This project follows
48 | [Google's Open Source Community Guidelines](https://opensource.google/conduct/).
49 |
50 | We pledge to maintain an open and welcoming environment. For details, see our
51 | [code of conduct](https://dart.dev/code-of-conduct).
52 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2024, the Dart project authors.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are
5 | met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above
10 | copyright notice, this list of conditions and the following
11 | disclaimer in the documentation and/or other materials provided
12 | with the distribution.
13 | * Neither the name of Google LLC nor the names of its
14 | contributors may be used to endorse or promote products derived
15 | from this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | ## Overview
4 |
5 | > [!IMPORTANT]
6 | > This repository was a work-in-progress prototype for the
7 | > [macros](https://github.com/dart-lang/language/blob/b268fe0380995b074176e335beec476553eb3c04/working/macros/feature-specification.md)
8 | > feature, which was [canceled](https://medium.com/dartlang/an-update-on-dart-macros-data-serialization-06d3037d4f12)
9 | > in January 2025.
10 |
11 | For related work, see:
12 |
13 | - [Augmentations](https://github.com/dart-lang/language/blob/main/working/augmentation-libraries/feature-specification.md) feature
14 | - [`build_runner`](https://github.com/dart-lang/build/issues/3800) performance improvements
15 | - [Static Metaprogramming](https://github.com/dart-lang/language/issues/1482) feature request
16 |
17 | ## Packages
18 |
19 | | Package | Description | Version |
20 | |---|---|---|
21 | | [_analyzer_macros](pkgs/_analyzer_macros/) | Macro support for the analyzer. | |
22 | | [_cfe_macros](pkgs/_cfe_macros/) | Macro support for the CFE. | |
23 | | [_macro_builder](pkgs/_macro_builder/) | Builds macros. | |
24 | | [_macro_client](pkgs/_macro_client/) | Connects user macro code to a macro host. | |
25 | | [_macro_host](pkgs/_macro_host/) | Hosts macros. | |
26 | | [_macro_runner](pkgs/_macro_runner/) | Runs macros. | |
27 | | [_macro_server](pkgs/_macro_server/) | Serves a `macro_service`. | |
28 | | [_test_macros](pkgs/_test_macros/) | Some test macros. | |
29 | | [dart_model](pkgs/dart_model/) | Data model for information about Dart code, queries about Dart code and augmentations to Dart code. Serializable with a versioned JSON schema for use by macros, generators and other tools. | [](https://pub.dev/packages/dart_model) |
30 | | [macro](pkgs/macro/) | For implementing a macro. | [](https://pub.dev/packages/macro) |
31 | | [macro_service](pkgs/macro_service/) | Macro communication with the macro host. | [](https://pub.dev/packages/macro_service) |
32 | | [generate_dart_model](tool/dart_model_generator/) | | |
33 |
34 | ## Publishing automation
35 |
36 | For information about our publishing automation and release process, see
37 | https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.
38 |
39 | For additional information about contributing, see our
40 | [contributing](CONTRIBUTING.md) page.
41 |
--------------------------------------------------------------------------------
/goldens/README.md:
--------------------------------------------------------------------------------
1 | # Golden Tests
2 |
3 | Each `.dart` file under this path creates a test case in
4 | `pkgs/_analyzer_macros/test/golden_test.dart` and
5 | `pkgs/_cfe_macros/test/golden_test.dart`.
6 |
7 | The test case looks for golden files next to the `.dart` file and asserts
8 | that they match.
9 |
10 | ## Introspection
11 |
12 | To test introspection, add `.analyzer.json` and/or `.cfe.json` golden files.
13 | The JSON in the golden file is compared with the query output on the `.dart`
14 | file, which must be tagged with the `QueryClass` macro.
15 |
16 | ## Application
17 |
18 | To test macro application, add `.analyzer.augmentations` and/or
19 | `.cfe.augmentations` golden files. These are compared with the full
20 | macro augmentation output of the corresponding `.dart` file.
21 |
--------------------------------------------------------------------------------
/goldens/foo/analysis_options.yaml:
--------------------------------------------------------------------------------
1 | analyzer:
2 | enable-experiment:
3 | - enhanced-parts
4 | - macros
5 |
--------------------------------------------------------------------------------
/goldens/foo/lib/built_value/built_value_test.analyzer.augmentations:
--------------------------------------------------------------------------------
1 | part of 'package:foo/built_value/built_value_test.dart';
2 |
3 | import 'package:_test_macros/built_value.dart' as prefix0;
4 | import 'package:foo/built_value/built_value_test.dart' as prefix1;
5 | import 'dart:core' as prefix2;
6 |
7 | @prefix0.BuiltValueBuilder()
8 | class EmptyBuilder {}
9 |
10 | @prefix0.BuiltValueBuilder()
11 | class PrimitiveFieldsBuilder {}
12 |
13 | @prefix0.BuiltValueBuilder()
14 | class NestedFieldsBuilder {}
15 |
16 | augment class Empty {
17 | factory Empty([void Function(prefix1.EmptyBuilder)? updates]) =>
18 | (prefix1.EmptyBuilder()..update(updates)).build();
19 | Empty._() {}
20 |
21 | prefix1.EmptyBuilder toBuilder() => prefix1.EmptyBuilder()..replace(this);
22 | prefix1.Empty rebuild(void Function(prefix1.EmptyBuilder) updates) =>
23 | (toBuilder()..update(updates)).build();
24 |
25 | prefix2.int get hashCode => prefix2.Object.hashAll([]);
26 |
27 | prefix2.bool operator==(prefix2.Object other) =>
28 | other is prefix1.Empty;
29 |
30 | prefix2.String toString() => 'Empty()';
31 |
32 | }
33 | augment class PrimitiveFields {
34 | factory PrimitiveFields([void Function(prefix1.PrimitiveFieldsBuilder)? updates]) =>
35 | (prefix1.PrimitiveFieldsBuilder()..update(updates)).build();
36 | PrimitiveFields._({required this.anInt,required this.aString,required this.aNullableString,}) {}
37 |
38 | prefix1.PrimitiveFieldsBuilder toBuilder() => prefix1.PrimitiveFieldsBuilder()..replace(this);
39 | prefix1.PrimitiveFields rebuild(void Function(prefix1.PrimitiveFieldsBuilder) updates) =>
40 | (toBuilder()..update(updates)).build();
41 |
42 | prefix2.int get hashCode => prefix2.Object.hashAll([anInt,aString,aNullableString,]);
43 |
44 | prefix2.bool operator==(prefix2.Object other) =>
45 | other is prefix1.PrimitiveFields&& anInt == other.anInt&& aString == other.aString&& aNullableString == other.aNullableString;
46 |
47 | prefix2.String toString() => 'PrimitiveFields(anInt: $anInt, aString: $aString, aNullableString: $aNullableString)';
48 |
49 | }
50 | augment class NestedFields {
51 | factory NestedFields([void Function(prefix1.NestedFieldsBuilder)? updates]) =>
52 | (prefix1.NestedFieldsBuilder()..update(updates)).build();
53 | NestedFields._({required this.aPrimitiveFields,required this.stringWrapper,required this.aString,}) {}
54 |
55 | prefix1.NestedFieldsBuilder toBuilder() => prefix1.NestedFieldsBuilder()..replace(this);
56 | prefix1.NestedFields rebuild(void Function(prefix1.NestedFieldsBuilder) updates) =>
57 | (toBuilder()..update(updates)).build();
58 |
59 | prefix2.int get hashCode => prefix2.Object.hashAll([aPrimitiveFields,stringWrapper,aString,]);
60 |
61 | prefix2.bool operator==(prefix2.Object other) =>
62 | other is prefix1.NestedFields&& aPrimitiveFields == other.aPrimitiveFields&& stringWrapper == other.stringWrapper&& aString == other.aString;
63 |
64 | prefix2.String toString() => 'NestedFields(aPrimitiveFields: $aPrimitiveFields, stringWrapper: $stringWrapper, aString: $aString)';
65 |
66 | }
67 | augment class NestedFieldsBuilder {
68 | prefix1.PrimitiveFieldsBuilder aPrimitiveFields = prefix1.PrimitiveFieldsBuilder();prefix1.StringWrapper? stringWrapper;prefix2.String? aString;
69 |
70 | void replace(prefix1.NestedFields other) { this.aPrimitiveFields = other.aPrimitiveFields.toBuilder();this.stringWrapper = other.stringWrapper;this.aString = other.aString; }
71 | void update(void Function(prefix1.NestedFieldsBuilder)? updates) => updates?.call(this);
72 | prefix1.NestedFields build() => prefix1.NestedFields._(aPrimitiveFields: aPrimitiveFields.build(),stringWrapper: stringWrapper!,aString: aString!,);
73 |
74 | }
75 | augment class PrimitiveFieldsBuilder {
76 | prefix2.int? anInt;prefix2.String? aString;prefix2.String? aNullableString;
77 |
78 | void replace(prefix1.PrimitiveFields other) { this.anInt = other.anInt;this.aString = other.aString;this.aNullableString = other.aNullableString; }
79 | void update(void Function(prefix1.PrimitiveFieldsBuilder)? updates) => updates?.call(this);
80 | prefix1.PrimitiveFields build() => prefix1.PrimitiveFields._(anInt: anInt!,aString: aString!,aNullableString: aNullableString,);
81 |
82 | }
83 | augment class EmptyBuilder {
84 |
85 |
86 | void replace(prefix1.Empty other) { }
87 | void update(void Function(prefix1.EmptyBuilder)? updates) => updates?.call(this);
88 | prefix1.Empty build() => prefix1.Empty._();
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/goldens/foo/lib/built_value/built_value_test.dart:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2 | // for details. All rights reserved. Use of this source code is governed by a
3 | // BSD-style license that can be found in the LICENSE file.
4 |
5 | import 'package:_test_macros/built_value.dart';
6 | import 'package:test/test.dart';
7 |
8 | void main() {
9 | group('Empty class', () {
10 | test('instantiation, builder, rebuild, comparison', () {
11 | final value = Empty();
12 | final sameValue = value.rebuild((b) {});
13 | expect(sameValue, value);
14 |
15 | // analyzer: The function 'EmptyBuilder' isn't defined.
16 | // final valueBuilder = EmptyBuilder();
17 | // final value3 = valueBuilder.build();
18 | // expect(value3, value);
19 | });
20 | });
21 |
22 | group('Class with primitive fields', () {
23 | test('instantiation, builder, rebuild, comparison, hash code, '
24 | 'toString', () {
25 | final value = PrimitiveFields(
26 | (b) =>
27 | b
28 | ..anInt = 3
29 | ..aString = 'four',
30 | );
31 | final value2 = value.rebuild(
32 | (b) =>
33 | b
34 | ..anInt = 4
35 | ..aString = 'five',
36 | );
37 | expect(value2, isNot(value));
38 | expect(value2.hashCode, isNot(value.hashCode));
39 | expect(
40 | value2.toString(),
41 | 'PrimitiveFields(anInt: 4, aString: five, aNullableString: null)',
42 | );
43 |
44 | final sameValue = value.rebuild((b) => b);
45 | expect(sameValue, value);
46 | expect(sameValue.hashCode, value.hashCode);
47 | });
48 | });
49 |
50 | group('Class with nested fields', () {
51 | test('has nested builder', () {
52 | final value = NestedFields(
53 | (b) =>
54 | b
55 | ..aPrimitiveFields.anInt = 3
56 | ..aPrimitiveFields.aString = 'four'
57 | ..aString = 'five'
58 | ..stringWrapper = StringWrapper('six'),
59 | );
60 | expect(
61 | value.toString(),
62 | 'NestedFields(aPrimitiveFields: PrimitiveFields('
63 | 'anInt: 3, aString: four, aNullableString: null), '
64 | 'stringWrapper: StringWrapper(aString: six), aString: five)',
65 | );
66 | });
67 | });
68 | }
69 |
70 | class NonMacro {
71 | const NonMacro();
72 | }
73 |
74 | @NonMacro()
75 | class StringWrapper {
76 | const StringWrapper(this.aString);
77 |
78 | final String aString;
79 |
80 | @override
81 | String toString() => 'StringWrapper(aString: $aString)';
82 | }
83 |
84 | @BuiltValue()
85 | class Empty {}
86 |
87 | @BuiltValue()
88 | class PrimitiveFields {
89 | final int anInt;
90 | final String aString;
91 | final String? aNullableString;
92 | }
93 |
94 | @BuiltValue()
95 | class NestedFields {
96 | final PrimitiveFields aPrimitiveFields;
97 | final StringWrapper stringWrapper;
98 | final String aString;
99 | }
100 |
--------------------------------------------------------------------------------
/goldens/foo/lib/declare_x.analyzer.augmentations:
--------------------------------------------------------------------------------
1 | part of 'package:foo/declare_x.dart';
2 |
3 | augment class Foo {
4 | int get x => 3;
5 | }
6 |
--------------------------------------------------------------------------------
/goldens/foo/lib/declare_x.cfe.augmentations:
--------------------------------------------------------------------------------
1 | augment library 'package:foo/declare_x.dart';
2 |
3 | augment class Foo {
4 | int get x => 3;
5 | }
6 |
--------------------------------------------------------------------------------
/goldens/foo/lib/declare_x.dart:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2 | // for details. All rights reserved. Use of this source code is governed by a
3 | // BSD-style license that can be found in the LICENSE file.
4 |
5 | import 'package:_test_macros/declare_x_macro.dart';
6 |
7 | @DeclareX()
8 | class Foo {}
9 |
10 | void main() => print(Foo().x);
11 |
--------------------------------------------------------------------------------
/goldens/foo/lib/foo.cfe.json:
--------------------------------------------------------------------------------
1 | {
2 | "uris": {
3 | "package:foo/foo.dart": {
4 | "scopes": {
5 | "Foo": {
6 | "members": {
7 | "bar": {
8 | "properties": {
9 | "isAbstract": false,
10 | "isGetter": false,
11 | "isField": true,
12 | "isMethod": false,
13 | "isStatic": false
14 | }
15 | }
16 | },
17 | "properties": {
18 | "isClass": true
19 | }
20 | },
21 | "Bar": {
22 | "members": {
23 | "bar": {
24 | "properties": {
25 | "isAbstract": false,
26 | "isGetter": false,
27 | "isField": true,
28 | "isMethod": false,
29 | "isStatic": false
30 | }
31 | }
32 | },
33 | "properties": {
34 | "isClass": true
35 | }
36 | }
37 | }
38 | }
39 | },
40 | "types": {
41 | "named": {
42 | "package:foo/foo.dart#Foo": {
43 | "typeParameters": [],
44 | "self": {
45 | "name": {
46 | "uri": "package:foo/foo.dart",
47 | "name": "Foo"
48 | },
49 | "instantiation": []
50 | },
51 | "supertypes": [
52 | {
53 | "name": {
54 | "uri": "dart:core",
55 | "name": "Object"
56 | },
57 | "instantiation": []
58 | }
59 | ]
60 | },
61 | "dart:core#Object": {
62 | "typeParameters": [],
63 | "self": {
64 | "name": {
65 | "uri": "dart:core",
66 | "name": "Object"
67 | },
68 | "instantiation": []
69 | },
70 | "supertypes": []
71 | },
72 | "dart:core#Null": {
73 | "typeParameters": [],
74 | "self": {
75 | "name": {
76 | "uri": "dart:core",
77 | "name": "Null"
78 | },
79 | "instantiation": []
80 | },
81 | "supertypes": [
82 | {
83 | "name": {
84 | "uri": "dart:core",
85 | "name": "Object"
86 | },
87 | "instantiation": []
88 | }
89 | ]
90 | },
91 | "dart:async#Future": {
92 | "typeParameters": [
93 | {
94 | "identifier": 0,
95 | "bound": {
96 | "type": "NullableTypeDesc",
97 | "value": {
98 | "inner": {
99 | "type": "NamedTypeDesc",
100 | "value": {
101 | "name": {
102 | "uri": "dart:core",
103 | "name": "Object"
104 | },
105 | "instantiation": []
106 | }
107 | }
108 | }
109 | }
110 | }
111 | ],
112 | "self": {
113 | "name": {
114 | "uri": "dart:async",
115 | "name": "Future"
116 | },
117 | "instantiation": [
118 | {
119 | "type": "TypeParameterTypeDesc",
120 | "value": {
121 | "parameterId": 0
122 | }
123 | }
124 | ]
125 | },
126 | "supertypes": [
127 | {
128 | "name": {
129 | "uri": "dart:core",
130 | "name": "Object"
131 | },
132 | "instantiation": []
133 | }
134 | ]
135 | },
136 | "package:foo/foo.dart#Bar": {
137 | "typeParameters": [],
138 | "self": {
139 | "name": {
140 | "uri": "package:foo/foo.dart",
141 | "name": "Bar"
142 | },
143 | "instantiation": []
144 | },
145 | "supertypes": [
146 | {
147 | "name": {
148 | "uri": "dart:core",
149 | "name": "Object"
150 | },
151 | "instantiation": []
152 | }
153 | ]
154 | }
155 | }
156 | }
157 | }
--------------------------------------------------------------------------------
/goldens/foo/lib/foo.dart:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2 | // for details. All rights reserved. Use of this source code is governed by a
3 | // BSD-style license that can be found in the LICENSE file.
4 |
5 | import 'package:_test_macros/query_class.dart';
6 |
7 | @QueryClass()
8 | class Foo {
9 | final int bar = 3;
10 |
11 | Foo.construct(int x, {required int y});
12 | Foo.construct2(int x, [String? y]);
13 |
14 | void method(int x, {int? y}) {}
15 | Bar? method2(int x, [String? y]) {
16 | return null;
17 | }
18 | }
19 |
20 | @QueryClass()
21 | class Bar {
22 | final int bar = 4;
23 | }
24 |
--------------------------------------------------------------------------------
/goldens/foo/lib/literal_params.analyzer.augmentations:
--------------------------------------------------------------------------------
1 | part of 'package:foo/literal_params.dart';
2 |
3 | augment class Foo {
4 | // anInt: 7, int
5 | // aNum: 8.0, double
6 | // aDouble: 9.0, double
7 | // aString: 10, String
8 | // anObject: {type: {type: NamedTypeAnnotation, value: {reference: {type: ClassReference, value: {name: Bar}}, typeArguments: []}}, constructor: {type: ConstructorReference, value: {name: new}}, arguments: [{type: NamedArgument, value: {name: a, expression: {type: BooleanLiteral, value: {value: true}}}}, {type: NamedArgument, value: {name: b, expression: {type: BooleanLiteral, value: {value: false}}}}]}, String
9 | // ints: [11, 12], List