diff --git a/.github/workflows/code_builder.yaml b/.github/workflows/code_builder.yaml index 04addcdae..ad3280108 100644 --- a/.github/workflows/code_builder.yaml +++ b/.github/workflows/code_builder.yaml @@ -51,7 +51,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - sdk: [3.6.0, dev] + sdk: [3.7.0, dev] steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c diff --git a/pkgs/code_builder/CHANGELOG.md b/pkgs/code_builder/CHANGELOG.md index 893d23f50..ddd8505be 100644 --- a/pkgs/code_builder/CHANGELOG.md +++ b/pkgs/code_builder/CHANGELOG.md @@ -1,11 +1,17 @@ -## 4.10.2-wip +## 4.11.0 +* Export `SpecVisitor`, `ClosureExpression`, `LiteralMapExpression` + `LiteralRecordExpression`, `LiteralSetExpression` types. * Support `Expression.newInstanceNamed` with empty name * Consistently add blank lines between `=>` in class-like definitions. * Fixed bug: Fields declared with `static` and `external` now produce code with correct order -* Upgrade `dart_style` and `source_gen` to remove `package:macros` dependency. -* Require Dart `^3.6.0` due to the upgrades. +* Require `built_collection: ^5.1.1` +* Require `built_value: ^8.10.1` +* Require `collection: ^1.19.0` +* Require `matcher: ^0.12.16+1` +* Require `meta: ^1.16.0` +* Require `sdk: ^3.7.0` ## 4.10.1 diff --git a/pkgs/code_builder/analysis_options.yaml b/pkgs/code_builder/analysis_options.yaml index d052c68a8..8bbd1b716 100644 --- a/pkgs/code_builder/analysis_options.yaml +++ b/pkgs/code_builder/analysis_options.yaml @@ -22,4 +22,5 @@ linter: - prefer_expression_function_bodies - prefer_final_locals - unnecessary_await_in_return + - unnecessary_ignore - use_string_buffers diff --git a/pkgs/code_builder/example/example.dart b/pkgs/code_builder/example/example.dart index 6f73598e9..ac54beff5 100644 --- a/pkgs/code_builder/example/example.dart +++ b/pkgs/code_builder/example/example.dart @@ -23,12 +23,20 @@ void main() { /// } /// ``` String animalClass() { - final animal = Class((b) => b - ..name = 'Animal' - ..extend = refer('Organism') - ..methods.add(Method.returnsVoid((b) => b - ..name = 'eat' - ..body = refer('print').call([literalString('Yum!')]).code))); + final animal = Class( + (b) => + b + ..name = 'Animal' + ..extend = refer('Organism') + ..methods.add( + Method.returnsVoid( + (b) => + b + ..name = 'eat' + ..body = refer('print').call([literalString('Yum!')]).code, + ), + ), + ); return _dartfmt.format('${animal.accept(DartEmitter())}'); } @@ -43,14 +51,20 @@ String animalClass() { /// ``` String scopedLibrary() { final methods = [ - Method((b) => b - ..body = const Code('') - ..name = 'doThing' - ..returns = refer('Thing', 'package:a/a.dart')), - Method((b) => b - ..body = const Code('') - ..name = 'doOther' - ..returns = refer('Other', 'package:b/b.dart')), + Method( + (b) => + b + ..body = const Code('') + ..name = 'doThing' + ..returns = refer('Thing', 'package:a/a.dart'), + ), + Method( + (b) => + b + ..body = const Code('') + ..name = 'doOther' + ..returns = refer('Other', 'package:b/b.dart'), + ), ]; final library = Library((b) => b.body.addAll(methods)); return _dartfmt.format('${library.accept(DartEmitter.scoped())}'); @@ -68,19 +82,28 @@ String scopedLibrary() { /// ``` String jsonEnum() { final values = [ - EnumValue((b) => b - ..name = 'metric' - ..annotations.addAll([ - refer('JsonKey').call([literalString('m')]) - ])), - EnumValue((b) => b - ..name = 'imperial' - ..annotations.addAll([ - refer('JsonKey').call([literalString('i')]) - ])), + EnumValue( + (b) => + b + ..name = 'metric' + ..annotations.addAll([ + refer('JsonKey').call([literalString('m')]), + ]), + ), + EnumValue( + (b) => + b + ..name = 'imperial' + ..annotations.addAll([ + refer('JsonKey').call([literalString('i')]), + ]), + ), ]; - final e = Enum((b) => b - ..name = 'Unit' - ..values.addAll(values)); + final e = Enum( + (b) => + b + ..name = 'Unit' + ..values.addAll(values), + ); return _dartfmt.format('${e.accept(DartEmitter())}'); } diff --git a/pkgs/code_builder/lib/code_builder.dart b/pkgs/code_builder/lib/code_builder.dart index 9cd15b958..47d416c69 100644 --- a/pkgs/code_builder/lib/code_builder.dart +++ b/pkgs/code_builder/lib/code_builder.dart @@ -17,6 +17,7 @@ export 'src/specs/enum.dart' export 'src/specs/expression.dart' show BinaryExpression, + ClosureExpression, CodeExpression, Expression, ExpressionEmitter, @@ -25,6 +26,9 @@ export 'src/specs/expression.dart' InvokeExpressionType, LiteralExpression, LiteralListExpression, + LiteralMapExpression, + LiteralRecordExpression, + LiteralSetExpression, ParenthesizedExpression, ToCodeExpression, declareConst, @@ -70,3 +74,4 @@ export 'src/specs/type_function.dart' show FunctionType, FunctionTypeBuilder; export 'src/specs/type_record.dart' show RecordType, RecordTypeBuilder; export 'src/specs/type_reference.dart' show TypeReference, TypeReferenceBuilder; export 'src/specs/typedef.dart' show TypeDef, TypeDefBuilder; +export 'src/visitors.dart' show SpecVisitor; diff --git a/pkgs/code_builder/lib/src/allocator.dart b/pkgs/code_builder/lib/src/allocator.dart index 18d2d8c0d..2e732b361 100644 --- a/pkgs/code_builder/lib/src/allocator.dart +++ b/pkgs/code_builder/lib/src/allocator.dart @@ -90,7 +90,6 @@ class _PrefixedAllocator implements Allocator { int _nextKey() => _keys++; @override - Iterable get imports => _imports.keys.map( - (u) => Directive.import(u, as: '_i${_imports[u]}'), - ); + Iterable get imports => + _imports.keys.map((u) => Directive.import(u, as: '_i${_imports[u]}')); } diff --git a/pkgs/code_builder/lib/src/emitter.dart b/pkgs/code_builder/lib/src/emitter.dart index 5d94eb929..26fb2577b 100644 --- a/pkgs/code_builder/lib/src/emitter.dart +++ b/pkgs/code_builder/lib/src/emitter.dart @@ -76,19 +76,21 @@ class DartEmitter extends Object /// May specify an [Allocator] to use for references and imports, /// otherwise uses [Allocator.none] which never prefixes references and will /// not automatically emit import directives. - DartEmitter( - {this.allocator = Allocator.none, - this.orderDirectives = false, - bool useNullSafetySyntax = false}) - : _useNullSafetySyntax = useNullSafetySyntax; + DartEmitter({ + this.allocator = Allocator.none, + this.orderDirectives = false, + bool useNullSafetySyntax = false, + }) : _useNullSafetySyntax = useNullSafetySyntax; /// Creates a new instance of [DartEmitter] with simple automatic imports. - factory DartEmitter.scoped( - {bool orderDirectives = false, bool useNullSafetySyntax = false}) => - DartEmitter( - allocator: Allocator.simplePrefixing(), - orderDirectives: orderDirectives, - useNullSafetySyntax: useNullSafetySyntax); + factory DartEmitter.scoped({ + bool orderDirectives = false, + bool useNullSafetySyntax = false, + }) => DartEmitter( + allocator: Allocator.simplePrefixing(), + orderDirectives: orderDirectives, + useNullSafetySyntax: useNullSafetySyntax, + ); static bool _isLambdaBody(Code? code) => code is ToCodeExpression && !code.isStatement; @@ -145,13 +147,17 @@ class DartEmitter extends Object out ..write(' with ') ..writeAll( - spec.mixins.map((m) => m.type.accept(this)), ','); + spec.mixins.map((m) => m.type.accept(this)), + ',', + ); } if (spec.implements.isNotEmpty) { out ..write(' implements ') ..writeAll( - spec.implements.map((m) => m.type.accept(this)), ','); + spec.implements.map((m) => m.type.accept(this)), + ',', + ); } out.write(' {'); for (var c in spec.constructors) { @@ -188,7 +194,9 @@ class DartEmitter extends Object out ..write(' implements ') ..writeAll( - spec.implements.map((m) => m.type.accept(this)), ','); + spec.implements.map((m) => m.type.accept(this)), + ',', + ); } out.write(' {'); for (var f in spec.fields) { @@ -201,8 +209,11 @@ class DartEmitter extends Object } @override - StringSink visitConstructor(Constructor spec, String clazz, - [StringSink? output]) { + StringSink visitConstructor( + Constructor spec, + String clazz, [ + StringSink? output, + ]) { output ??= StringBuffer(); spec.docs.forEach(output.writeln); for (var a in spec.annotations) { @@ -342,7 +353,9 @@ class DartEmitter extends Object out ..write(' implements ') ..writeAll( - spec.implements.map((m) => m.type.accept(this)), ','); + spec.implements.map((m) => m.type.accept(this)), + ',', + ); } out.writeln(' {'); @@ -360,7 +373,9 @@ class DartEmitter extends Object } void _visitRepresentationDeclaration( - RepresentationDeclaration spec, StringSink out) { + RepresentationDeclaration spec, + StringSink out, + ) { spec.docs.forEach(out.writeln); for (var a in spec.annotations) { visitAnnotation(a, out); @@ -509,7 +524,8 @@ class DartEmitter extends Object Directive? previous; if (directives.any((d) => d.as?.startsWith('_') ?? false)) { output.writeln( - '// ignore_for_file: no_leading_underscores_for_library_prefixes'); + '// ignore_for_file: no_leading_underscores_for_library_prefixes', + ); } for (final directive in directives) { if (_newLineBetween(orderDirectives, previous, directive)) { @@ -543,7 +559,8 @@ class DartEmitter extends Object out.write('>'); } out.write('('); - final needsTrailingComma = spec.requiredParameters.length + + final needsTrailingComma = + spec.requiredParameters.length + spec.optionalParameters.length + spec.namedRequiredParameters.length + spec.namedParameters.length > @@ -551,7 +568,8 @@ class DartEmitter extends Object visitAll(spec.requiredParameters, out, (spec) { spec.accept(this, out); }); - final hasNamedParameters = spec.namedRequiredParameters.isNotEmpty || + final hasNamedParameters = + spec.namedRequiredParameters.isNotEmpty || spec.namedParameters.isNotEmpty; if (spec.requiredParameters.isNotEmpty && (needsTrailingComma || @@ -610,8 +628,9 @@ class DartEmitter extends Object out.write(', '); } out.write('{'); - visitAll>(spec.namedFieldTypes.entries, out, - (entry) { + visitAll>(spec.namedFieldTypes.entries, out, ( + entry, + ) { entry.value.accept(this, out); out.write(' ${entry.key}'); }); @@ -811,8 +830,10 @@ class DartEmitter extends Object } @override - StringSink visitTypeParameters(Iterable specs, - [StringSink? output]) { + StringSink visitTypeParameters( + Iterable specs, [ + StringSink? output, + ]) { output ??= StringBuffer(); if (specs.isNotEmpty) { output @@ -836,13 +857,17 @@ class DartEmitter extends Object out ..write(' with ') ..writeAll( - spec.mixins.map((m) => m.type.accept(this)), ', '); + spec.mixins.map((m) => m.type.accept(this)), + ', ', + ); } if (spec.implements.isNotEmpty) { out ..write(' implements ') ..writeAll( - spec.implements.map((m) => m.type.accept(this)), ', '); + spec.implements.map((m) => m.type.accept(this)), + ', ', + ); } out.write(' { '); for (var v in spec.values) { @@ -855,7 +880,8 @@ class DartEmitter extends Object out.write('.${v.constructorName}'); } visitTypeParameters(v.types.map((r) => r.type), out); - final takesArguments = v.constructorName != null || + final takesArguments = + v.constructorName != null || v.arguments.isNotEmpty || v.namedArguments.isNotEmpty; if (takesArguments) { @@ -863,7 +889,9 @@ class DartEmitter extends Object } if (v.arguments.isNotEmpty) { out.writeAll( - v.arguments.map((arg) => arg.accept(this)), ', '); + v.arguments.map((arg) => arg.accept(this)), + ', ', + ); } if (v.arguments.isNotEmpty && v.namedArguments.isNotEmpty) { out.write(', '); diff --git a/pkgs/code_builder/lib/src/matchers.dart b/pkgs/code_builder/lib/src/matchers.dart index 0cdf73997..fe48e2832 100644 --- a/pkgs/code_builder/lib/src/matchers.dart +++ b/pkgs/code_builder/lib/src/matchers.dart @@ -16,10 +16,7 @@ String _dart(Spec spec, DartEmitter emitter) => /// Both [source] and the result emitted from the compared [Spec] are formatted /// with [EqualsDart.format]. A plain [DartEmitter] is used by default and may /// be overridden with [emitter]. -Matcher equalsDart( - String source, [ - DartEmitter? emitter, -]) => +Matcher equalsDart(String source, [DartEmitter? emitter]) => EqualsDart._(EqualsDart._format(source), emitter ?? DartEmitter()); /// Implementation detail of using the [equalsDart] matcher. @@ -59,12 +56,9 @@ class EqualsDart extends Matcher { bool verbose, ) { final actualSource = _dart(item, _emitter); - return equals(_expectedSource).describeMismatch( - actualSource, - mismatchDescription, - matchState, - verbose, - ); + return equals( + _expectedSource, + ).describeMismatch(actualSource, mismatchDescription, matchState, verbose); } @override diff --git a/pkgs/code_builder/lib/src/specs/class.dart b/pkgs/code_builder/lib/src/specs/class.dart index 4c1915eaf..459496f0f 100644 --- a/pkgs/code_builder/lib/src/specs/class.dart +++ b/pkgs/code_builder/lib/src/specs/class.dart @@ -62,10 +62,7 @@ abstract class Class extends Object String get name; @override - R accept( - SpecVisitor visitor, [ - R? context, - ]) => + R accept(SpecVisitor visitor, [R? context]) => visitor.visitClass(this, context); } @@ -75,10 +72,10 @@ enum ClassModifier { interface; String get name => switch (this) { - ClassModifier.base => 'base', - ClassModifier.final$ => 'final', - ClassModifier.interface => 'interface' - }; + ClassModifier.base => 'base', + ClassModifier.final$ => 'final', + ClassModifier.interface => 'interface', + }; } abstract class ClassBuilder extends Object diff --git a/pkgs/code_builder/lib/src/specs/class.g.dart b/pkgs/code_builder/lib/src/specs/class.g.dart index 423f576ce..3a558a54f 100644 --- a/pkgs/code_builder/lib/src/specs/class.g.dart +++ b/pkgs/code_builder/lib/src/specs/class.g.dart @@ -39,22 +39,22 @@ class _$Class extends Class { factory _$Class([void Function(ClassBuilder)? updates]) => (new ClassBuilder()..update(updates)).build() as _$Class; - _$Class._( - {required this.abstract, - required this.sealed, - required this.mixin, - this.modifier, - required this.annotations, - required this.docs, - this.extend, - required this.implements, - required this.mixins, - required this.types, - required this.constructors, - required this.methods, - required this.fields, - required this.name}) - : super._() { + _$Class._({ + required this.abstract, + required this.sealed, + required this.mixin, + this.modifier, + required this.annotations, + required this.docs, + this.extend, + required this.implements, + required this.mixins, + required this.types, + required this.constructors, + required this.methods, + required this.fields, + required this.name, + }) : super._() { BuiltValueNullFieldError.checkNotNull(abstract, r'Class', 'abstract'); BuiltValueNullFieldError.checkNotNull(sealed, r'Class', 'sealed'); BuiltValueNullFieldError.checkNotNull(mixin, r'Class', 'mixin'); @@ -64,7 +64,10 @@ class _$Class extends Class { BuiltValueNullFieldError.checkNotNull(mixins, r'Class', 'mixins'); BuiltValueNullFieldError.checkNotNull(types, r'Class', 'types'); BuiltValueNullFieldError.checkNotNull( - constructors, r'Class', 'constructors'); + constructors, + r'Class', + 'constructors', + ); BuiltValueNullFieldError.checkNotNull(methods, r'Class', 'methods'); BuiltValueNullFieldError.checkNotNull(fields, r'Class', 'fields'); BuiltValueNullFieldError.checkNotNull(name, r'Class', 'name'); @@ -351,26 +354,36 @@ class _$ClassBuilder extends ClassBuilder { _$Class _build() { _$Class _$result; try { - _$result = _$v ?? + _$result = + _$v ?? new _$Class._( - abstract: BuiltValueNullFieldError.checkNotNull( - abstract, r'Class', 'abstract'), - sealed: BuiltValueNullFieldError.checkNotNull( - sealed, r'Class', 'sealed'), - mixin: BuiltValueNullFieldError.checkNotNull( - mixin, r'Class', 'mixin'), - modifier: modifier, - annotations: annotations.build(), - docs: docs.build(), - extend: extend, - implements: implements.build(), - mixins: mixins.build(), - types: types.build(), - constructors: constructors.build(), - methods: methods.build(), - fields: fields.build(), - name: BuiltValueNullFieldError.checkNotNull( - name, r'Class', 'name')); + abstract: BuiltValueNullFieldError.checkNotNull( + abstract, + r'Class', + 'abstract', + ), + sealed: BuiltValueNullFieldError.checkNotNull( + sealed, + r'Class', + 'sealed', + ), + mixin: BuiltValueNullFieldError.checkNotNull( + mixin, + r'Class', + 'mixin', + ), + modifier: modifier, + annotations: annotations.build(), + docs: docs.build(), + extend: extend, + implements: implements.build(), + mixins: mixins.build(), + types: types.build(), + constructors: constructors.build(), + methods: methods.build(), + fields: fields.build(), + name: BuiltValueNullFieldError.checkNotNull(name, r'Class', 'name'), + ); } catch (_) { late String _$failedField; try { @@ -393,7 +406,10 @@ class _$ClassBuilder extends ClassBuilder { fields.build(); } catch (e) { throw new BuiltValueNestedFieldError( - r'Class', _$failedField, e.toString()); + r'Class', + _$failedField, + e.toString(), + ); } rethrow; } diff --git a/pkgs/code_builder/lib/src/specs/code.dart b/pkgs/code_builder/lib/src/specs/code.dart index 521eb1fe0..070c5700f 100644 --- a/pkgs/code_builder/lib/src/specs/code.dart +++ b/pkgs/code_builder/lib/src/specs/code.dart @@ -36,9 +36,7 @@ abstract class Code implements Spec { /// return '${a.allocate(fooType)}()' /// }); /// ``` - const factory Code.scope( - String Function(Allocate) scope, - ) = ScopedCode._; + const factory Code.scope(String Function(Allocate) scope) = ScopedCode._; @override R accept(covariant CodeVisitor visitor, [R? context]); diff --git a/pkgs/code_builder/lib/src/specs/code.g.dart b/pkgs/code_builder/lib/src/specs/code.g.dart index 7b5ba7825..27d3f4567 100644 --- a/pkgs/code_builder/lib/src/specs/code.g.dart +++ b/pkgs/code_builder/lib/src/specs/code.g.dart @@ -41,8 +41,7 @@ class _$Block extends Block { @override String toString() { return (newBuiltValueToStringHelper(r'Block') - ..add('statements', statements)) - .toString(); + ..add('statements', statements)).toString(); } } @@ -97,7 +96,10 @@ class _$BlockBuilder extends BlockBuilder { statements.build(); } catch (e) { throw new BuiltValueNestedFieldError( - r'Block', _$failedField, e.toString()); + r'Block', + _$failedField, + e.toString(), + ); } rethrow; } diff --git a/pkgs/code_builder/lib/src/specs/constructor.g.dart b/pkgs/code_builder/lib/src/specs/constructor.g.dart index 3f0693272..4a72a0207 100644 --- a/pkgs/code_builder/lib/src/specs/constructor.g.dart +++ b/pkgs/code_builder/lib/src/specs/constructor.g.dart @@ -35,29 +35,41 @@ class _$Constructor extends Constructor { factory _$Constructor([void Function(ConstructorBuilder)? updates]) => (new ConstructorBuilder()..update(updates)).build() as _$Constructor; - _$Constructor._( - {required this.annotations, - required this.docs, - required this.optionalParameters, - required this.requiredParameters, - required this.initializers, - this.body, - required this.external, - required this.constant, - required this.factory, - this.lambda, - this.name, - this.redirect}) - : super._() { + _$Constructor._({ + required this.annotations, + required this.docs, + required this.optionalParameters, + required this.requiredParameters, + required this.initializers, + this.body, + required this.external, + required this.constant, + required this.factory, + this.lambda, + this.name, + this.redirect, + }) : super._() { BuiltValueNullFieldError.checkNotNull( - annotations, r'Constructor', 'annotations'); + annotations, + r'Constructor', + 'annotations', + ); BuiltValueNullFieldError.checkNotNull(docs, r'Constructor', 'docs'); BuiltValueNullFieldError.checkNotNull( - optionalParameters, r'Constructor', 'optionalParameters'); + optionalParameters, + r'Constructor', + 'optionalParameters', + ); BuiltValueNullFieldError.checkNotNull( - requiredParameters, r'Constructor', 'requiredParameters'); + requiredParameters, + r'Constructor', + 'requiredParameters', + ); BuiltValueNullFieldError.checkNotNull( - initializers, r'Constructor', 'initializers'); + initializers, + r'Constructor', + 'initializers', + ); BuiltValueNullFieldError.checkNotNull(external, r'Constructor', 'external'); BuiltValueNullFieldError.checkNotNull(constant, r'Constructor', 'constant'); BuiltValueNullFieldError.checkNotNull(factory, r'Constructor', 'factory'); @@ -312,23 +324,34 @@ class _$ConstructorBuilder extends ConstructorBuilder { _$Constructor _build() { _$Constructor _$result; try { - _$result = _$v ?? + _$result = + _$v ?? new _$Constructor._( - annotations: annotations.build(), - docs: docs.build(), - optionalParameters: optionalParameters.build(), - requiredParameters: requiredParameters.build(), - initializers: initializers.build(), - body: body, - external: BuiltValueNullFieldError.checkNotNull( - external, r'Constructor', 'external'), - constant: BuiltValueNullFieldError.checkNotNull( - constant, r'Constructor', 'constant'), - factory: BuiltValueNullFieldError.checkNotNull( - factory, r'Constructor', 'factory'), - lambda: lambda, - name: name, - redirect: redirect); + annotations: annotations.build(), + docs: docs.build(), + optionalParameters: optionalParameters.build(), + requiredParameters: requiredParameters.build(), + initializers: initializers.build(), + body: body, + external: BuiltValueNullFieldError.checkNotNull( + external, + r'Constructor', + 'external', + ), + constant: BuiltValueNullFieldError.checkNotNull( + constant, + r'Constructor', + 'constant', + ), + factory: BuiltValueNullFieldError.checkNotNull( + factory, + r'Constructor', + 'factory', + ), + lambda: lambda, + name: name, + redirect: redirect, + ); } catch (_) { late String _$failedField; try { @@ -344,7 +367,10 @@ class _$ConstructorBuilder extends ConstructorBuilder { initializers.build(); } catch (e) { throw new BuiltValueNestedFieldError( - r'Constructor', _$failedField, e.toString()); + r'Constructor', + _$failedField, + e.toString(), + ); } rethrow; } diff --git a/pkgs/code_builder/lib/src/specs/directive.dart b/pkgs/code_builder/lib/src/specs/directive.dart index e10c0ea2a..fb1d07742 100644 --- a/pkgs/code_builder/lib/src/specs/directive.dart +++ b/pkgs/code_builder/lib/src/specs/directive.dart @@ -21,46 +21,58 @@ abstract class Directive String? as, List show = const [], List hide = const [], - }) => - Directive((builder) => builder - ..as = as - ..type = DirectiveType.import - ..url = url - ..show.addAll(show) - ..hide.addAll(hide)); + }) => Directive( + (builder) => + builder + ..as = as + ..type = DirectiveType.import + ..url = url + ..show.addAll(show) + ..hide.addAll(hide), + ); factory Directive.importDeferredAs( String url, String as, { List show = const [], List hide = const [], - }) => - Directive((builder) => builder - ..as = as - ..type = DirectiveType.import - ..url = url - ..deferred = true - ..show.addAll(show) - ..hide.addAll(hide)); + }) => Directive( + (builder) => + builder + ..as = as + ..type = DirectiveType.import + ..url = url + ..deferred = true + ..show.addAll(show) + ..hide.addAll(hide), + ); factory Directive.export( String url, { List show = const [], List hide = const [], - }) => - Directive((builder) => builder - ..type = DirectiveType.export - ..url = url - ..show.addAll(show) - ..hide.addAll(hide)); - - factory Directive.part(String url) => Directive((builder) => builder - ..type = DirectiveType.part - ..url = url); - - factory Directive.partOf(String url) => Directive((builder) => builder - ..type = DirectiveType.partOf - ..url = url); + }) => Directive( + (builder) => + builder + ..type = DirectiveType.export + ..url = url + ..show.addAll(show) + ..hide.addAll(hide), + ); + + factory Directive.part(String url) => Directive( + (builder) => + builder + ..type = DirectiveType.part + ..url = url, + ); + + factory Directive.partOf(String url) => Directive( + (builder) => + builder + ..type = DirectiveType.partOf + ..url = url, + ); Directive._(); @@ -77,10 +89,7 @@ abstract class Directive bool get deferred; @override - R accept( - SpecVisitor visitor, [ - R? context, - ]) => + R accept(SpecVisitor visitor, [R? context]) => visitor.visitDirective(this, context); @override @@ -106,12 +115,7 @@ abstract class DirectiveBuilder DirectiveType? type; } -enum DirectiveType { - import, - export, - part, - partOf, -} +enum DirectiveType { import, export, part, partOf } /// Sort import URIs represented by [a] and [b] to honor the /// "Effective Dart" ordering rules which are enforced by the diff --git a/pkgs/code_builder/lib/src/specs/directive.g.dart b/pkgs/code_builder/lib/src/specs/directive.g.dart index b28158e07..0cc014a0c 100644 --- a/pkgs/code_builder/lib/src/specs/directive.g.dart +++ b/pkgs/code_builder/lib/src/specs/directive.g.dart @@ -23,14 +23,14 @@ class _$Directive extends Directive { factory _$Directive([void Function(DirectiveBuilder)? updates]) => (new DirectiveBuilder()..update(updates)).build() as _$Directive; - _$Directive._( - {this.as, - required this.url, - required this.type, - required this.show, - required this.hide, - required this.deferred}) - : super._() { + _$Directive._({ + this.as, + required this.url, + required this.type, + required this.show, + required this.hide, + required this.deferred, + }) : super._() { BuiltValueNullFieldError.checkNotNull(url, r'Directive', 'url'); BuiltValueNullFieldError.checkNotNull(type, r'Directive', 'type'); BuiltValueNullFieldError.checkNotNull(show, r'Directive', 'show'); @@ -189,19 +189,32 @@ class _$DirectiveBuilder extends DirectiveBuilder { Directive build() => _build(); _$Directive _build() { - final _$result = _$v ?? + final _$result = + _$v ?? new _$Directive._( - as: as, - url: - BuiltValueNullFieldError.checkNotNull(url, r'Directive', 'url'), - type: BuiltValueNullFieldError.checkNotNull( - type, r'Directive', 'type'), - show: BuiltValueNullFieldError.checkNotNull( - show, r'Directive', 'show'), - hide: BuiltValueNullFieldError.checkNotNull( - hide, r'Directive', 'hide'), - deferred: BuiltValueNullFieldError.checkNotNull( - deferred, r'Directive', 'deferred')); + as: as, + url: BuiltValueNullFieldError.checkNotNull(url, r'Directive', 'url'), + type: BuiltValueNullFieldError.checkNotNull( + type, + r'Directive', + 'type', + ), + show: BuiltValueNullFieldError.checkNotNull( + show, + r'Directive', + 'show', + ), + hide: BuiltValueNullFieldError.checkNotNull( + hide, + r'Directive', + 'hide', + ), + deferred: BuiltValueNullFieldError.checkNotNull( + deferred, + r'Directive', + 'deferred', + ), + ); replace(_$result); return _$result; } diff --git a/pkgs/code_builder/lib/src/specs/enum.dart b/pkgs/code_builder/lib/src/specs/enum.dart index c58f92cb0..82562ee79 100644 --- a/pkgs/code_builder/lib/src/specs/enum.dart +++ b/pkgs/code_builder/lib/src/specs/enum.dart @@ -6,11 +6,16 @@ import 'package:built_collection/built_collection.dart'; import 'package:built_value/built_value.dart'; import 'package:meta/meta.dart'; -import '../../code_builder.dart'; +import '../base.dart' show Spec; import '../mixins/annotations.dart'; import '../mixins/dartdoc.dart'; import '../mixins/generics.dart'; import '../visitors.dart'; +import 'constructor.dart' show Constructor; +import 'expression.dart' show Expression; +import 'field.dart' show Field; +import 'method.dart' show Method; +import 'reference.dart' show Reference; part 'enum.g.dart'; @@ -44,10 +49,7 @@ abstract class Enum extends Object BuiltList get fields; @override - R accept( - SpecVisitor visitor, [ - R? context, - ]) => + R accept(SpecVisitor visitor, [R? context]) => visitor.visitEnum(this, context); } diff --git a/pkgs/code_builder/lib/src/specs/enum.g.dart b/pkgs/code_builder/lib/src/specs/enum.g.dart index 651cc610a..8c2e35830 100644 --- a/pkgs/code_builder/lib/src/specs/enum.g.dart +++ b/pkgs/code_builder/lib/src/specs/enum.g.dart @@ -31,18 +31,18 @@ class _$Enum extends Enum { factory _$Enum([void Function(EnumBuilder)? updates]) => (new EnumBuilder()..update(updates)).build() as _$Enum; - _$Enum._( - {required this.name, - required this.values, - required this.annotations, - required this.docs, - required this.implements, - required this.mixins, - required this.types, - required this.constructors, - required this.methods, - required this.fields}) - : super._() { + _$Enum._({ + required this.name, + required this.values, + required this.annotations, + required this.docs, + required this.implements, + required this.mixins, + required this.types, + required this.constructors, + required this.methods, + required this.fields, + }) : super._() { BuiltValueNullFieldError.checkNotNull(name, r'Enum', 'name'); BuiltValueNullFieldError.checkNotNull(values, r'Enum', 'values'); BuiltValueNullFieldError.checkNotNull(annotations, r'Enum', 'annotations'); @@ -51,7 +51,10 @@ class _$Enum extends Enum { BuiltValueNullFieldError.checkNotNull(mixins, r'Enum', 'mixins'); BuiltValueNullFieldError.checkNotNull(types, r'Enum', 'types'); BuiltValueNullFieldError.checkNotNull( - constructors, r'Enum', 'constructors'); + constructors, + r'Enum', + 'constructors', + ); BuiltValueNullFieldError.checkNotNull(methods, r'Enum', 'methods'); BuiltValueNullFieldError.checkNotNull(fields, r'Enum', 'fields'); } @@ -273,19 +276,20 @@ class _$EnumBuilder extends EnumBuilder { _$Enum _build() { _$Enum _$result; try { - _$result = _$v ?? + _$result = + _$v ?? new _$Enum._( - name: - BuiltValueNullFieldError.checkNotNull(name, r'Enum', 'name'), - values: values.build(), - annotations: annotations.build(), - docs: docs.build(), - implements: implements.build(), - mixins: mixins.build(), - types: types.build(), - constructors: constructors.build(), - methods: methods.build(), - fields: fields.build()); + name: BuiltValueNullFieldError.checkNotNull(name, r'Enum', 'name'), + values: values.build(), + annotations: annotations.build(), + docs: docs.build(), + implements: implements.build(), + mixins: mixins.build(), + types: types.build(), + constructors: constructors.build(), + methods: methods.build(), + fields: fields.build(), + ); } catch (_) { late String _$failedField; try { @@ -309,7 +313,10 @@ class _$EnumBuilder extends EnumBuilder { fields.build(); } catch (e) { throw new BuiltValueNestedFieldError( - r'Enum', _$failedField, e.toString()); + r'Enum', + _$failedField, + e.toString(), + ); } rethrow; } @@ -337,23 +344,29 @@ class _$EnumValue extends EnumValue { factory _$EnumValue([void Function(EnumValueBuilder)? updates]) => (new EnumValueBuilder()..update(updates)).build() as _$EnumValue; - _$EnumValue._( - {required this.name, - required this.annotations, - required this.docs, - this.constructorName, - required this.types, - required this.arguments, - required this.namedArguments}) - : super._() { + _$EnumValue._({ + required this.name, + required this.annotations, + required this.docs, + this.constructorName, + required this.types, + required this.arguments, + required this.namedArguments, + }) : super._() { BuiltValueNullFieldError.checkNotNull(name, r'EnumValue', 'name'); BuiltValueNullFieldError.checkNotNull( - annotations, r'EnumValue', 'annotations'); + annotations, + r'EnumValue', + 'annotations', + ); BuiltValueNullFieldError.checkNotNull(docs, r'EnumValue', 'docs'); BuiltValueNullFieldError.checkNotNull(types, r'EnumValue', 'types'); BuiltValueNullFieldError.checkNotNull(arguments, r'EnumValue', 'arguments'); BuiltValueNullFieldError.checkNotNull( - namedArguments, r'EnumValue', 'namedArguments'); + namedArguments, + r'EnumValue', + 'namedArguments', + ); } @override @@ -525,16 +538,21 @@ class _$EnumValueBuilder extends EnumValueBuilder { _$EnumValue _build() { _$EnumValue _$result; try { - _$result = _$v ?? + _$result = + _$v ?? new _$EnumValue._( - name: BuiltValueNullFieldError.checkNotNull( - name, r'EnumValue', 'name'), - annotations: annotations.build(), - docs: docs.build(), - constructorName: constructorName, - types: types.build(), - arguments: arguments.build(), - namedArguments: namedArguments.build()); + name: BuiltValueNullFieldError.checkNotNull( + name, + r'EnumValue', + 'name', + ), + annotations: annotations.build(), + docs: docs.build(), + constructorName: constructorName, + types: types.build(), + arguments: arguments.build(), + namedArguments: namedArguments.build(), + ); } catch (_) { late String _$failedField; try { @@ -551,7 +569,10 @@ class _$EnumValueBuilder extends EnumValueBuilder { namedArguments.build(); } catch (e) { throw new BuiltValueNestedFieldError( - r'EnumValue', _$failedField, e.toString()); + r'EnumValue', + _$failedField, + e.toString(), + ); } rethrow; } diff --git a/pkgs/code_builder/lib/src/specs/expression.dart b/pkgs/code_builder/lib/src/specs/expression.dart index aa06de283..133609205 100644 --- a/pkgs/code_builder/lib/src/specs/expression.dart +++ b/pkgs/code_builder/lib/src/specs/expression.dart @@ -66,116 +66,69 @@ abstract class Expression implements Spec { /// Returns the result of `this` `as` [other]. Expression asA(Expression other) => - ParenthesizedExpression._(BinaryExpression._( - expression, - other, - 'as', - )); + ParenthesizedExpression._(BinaryExpression._(expression, other, 'as')); /// Returns accessing the index operator (`[]`) on `this`. Expression index(Expression index) => BinaryExpression._( - expression, - CodeExpression(Block.of([ - const Code('['), - index.code, - const Code(']'), - ])), - '', - ); + expression, + CodeExpression(Block.of([const Code('['), index.code, const Code(']')])), + '', + ); /// Returns the result of `this` `is` [other]. - Expression isA(Expression other) => BinaryExpression._( - expression, - other, - 'is', - ); + Expression isA(Expression other) => + BinaryExpression._(expression, other, 'is'); /// Returns the result of `this` `is!` [other]. - Expression isNotA(Expression other) => BinaryExpression._( - expression, - other, - 'is!', - ); + Expression isNotA(Expression other) => + BinaryExpression._(expression, other, 'is!'); /// Returns the result of `this` `==` [other]. - Expression equalTo(Expression other) => BinaryExpression._( - expression, - other, - '==', - ); + Expression equalTo(Expression other) => + BinaryExpression._(expression, other, '=='); /// Returns the result of `this` `!=` [other]. - Expression notEqualTo(Expression other) => BinaryExpression._( - expression, - other, - '!=', - ); + Expression notEqualTo(Expression other) => + BinaryExpression._(expression, other, '!='); /// Returns the result of `this` `>` [other]. - Expression greaterThan(Expression other) => BinaryExpression._( - expression, - other, - '>', - ); + Expression greaterThan(Expression other) => + BinaryExpression._(expression, other, '>'); /// Returns the result of `this` `<` [other]. - Expression lessThan(Expression other) => BinaryExpression._( - expression, - other, - '<', - ); + Expression lessThan(Expression other) => + BinaryExpression._(expression, other, '<'); /// Returns the result of `this` `>=` [other]. - Expression greaterOrEqualTo(Expression other) => BinaryExpression._( - expression, - other, - '>=', - ); + Expression greaterOrEqualTo(Expression other) => + BinaryExpression._(expression, other, '>='); /// Returns the result of `this` `<=` [other]. - Expression lessOrEqualTo(Expression other) => BinaryExpression._( - expression, - other, - '<=', - ); + Expression lessOrEqualTo(Expression other) => + BinaryExpression._(expression, other, '<='); /// Returns the result of `this` `+` [other]. - Expression operatorAdd(Expression other) => BinaryExpression._( - expression, - other, - '+', - ); + Expression operatorAdd(Expression other) => + BinaryExpression._(expression, other, '+'); /// Returns the result of `this` `-` [other]. - Expression operatorSubtract(Expression other) => BinaryExpression._( - expression, - other, - '-', - ); + Expression operatorSubtract(Expression other) => + BinaryExpression._(expression, other, '-'); @Deprecated('Use `operatorSubtract` instead') Expression operatorSubstract(Expression other) => operatorSubtract(other); /// Returns the result of `this` `/` [other]. - Expression operatorDivide(Expression other) => BinaryExpression._( - expression, - other, - '/', - ); + Expression operatorDivide(Expression other) => + BinaryExpression._(expression, other, '/'); /// Returns the result of `this` `*` [other]. - Expression operatorMultiply(Expression other) => BinaryExpression._( - expression, - other, - '*', - ); + Expression operatorMultiply(Expression other) => + BinaryExpression._(expression, other, '*'); /// Returns the result of `this` `%` [other]. - Expression operatorEuclideanModulo(Expression other) => BinaryExpression._( - expression, - other, - '%', - ); + Expression operatorEuclideanModulo(Expression other) => + BinaryExpression._(expression, other, '%'); /// Returns the result of `this` `~/` [other]. Expression operatorIntDivide(Expression other) => @@ -189,11 +142,7 @@ abstract class Expression implements Spec { ); /// This expression preceded by `await`. - Expression get awaited => BinaryExpression._( - _empty, - this, - 'await', - ); + Expression get awaited => BinaryExpression._(_empty, this, 'await'); /// Returns the result of `++this`. Expression operatorUnaryPrefixIncrement() => @@ -296,139 +245,118 @@ abstract class Expression implements Spec { BinaryExpression._(this, other, '|='); /// Return `{this} ?? {other}`. - Expression ifNullThen(Expression other) => BinaryExpression._( - this, - other, - '??', - ); + Expression ifNullThen(Expression other) => + BinaryExpression._(this, other, '??'); /// Return `{this} ??= {other}`. - Expression assignNullAware(Expression other) => BinaryExpression._( - this, - other, - '??=', - ); + Expression assignNullAware(Expression other) => + BinaryExpression._(this, other, '??='); /// Return `var {name} = {this}`. @Deprecated('Use `declareVar(name).assign(expression)`') Expression assignVar(String name, [Reference? type]) => BinaryExpression._( - type == null - ? LiteralExpression._('var $name') - : BinaryExpression._( - type.expression, - LiteralExpression._(name), - '', - ), - this, - '=', - ); + type == null + ? LiteralExpression._('var $name') + : BinaryExpression._(type.expression, LiteralExpression._(name), ''), + this, + '=', + ); /// Return `final {name} = {this}`. @Deprecated('Use `declareFinal(name).assign(expression)`') Expression assignFinal(String name, [Reference? type]) => BinaryExpression._( - type == null - ? const LiteralExpression._('final') - : BinaryExpression._( - const LiteralExpression._('final'), - type.expression, - '', - ), - this, - '$name =', - ); + type == null + ? const LiteralExpression._('final') + : BinaryExpression._( + const LiteralExpression._('final'), + type.expression, + '', + ), + this, + '$name =', + ); /// Return `const {name} = {this}`. @Deprecated('Use `declareConst(name).assign(expression)`') Expression assignConst(String name, [Reference? type]) => BinaryExpression._( - type == null - ? const LiteralExpression._('const') - : BinaryExpression._( - const LiteralExpression._('const'), - type.expression, - '', - ), - this, - '$name =', - isConst: true, - ); + type == null + ? const LiteralExpression._('const') + : BinaryExpression._( + const LiteralExpression._('const'), + type.expression, + '', + ), + this, + '$name =', + isConst: true, + ); /// Call this expression as a method. Expression call( Iterable positionalArguments, [ Map namedArguments = const {}, List typeArguments = const [], - ]) => - InvokeExpression._( - this, - positionalArguments.toList(), - namedArguments, - typeArguments, - ); + ]) => InvokeExpression._( + this, + positionalArguments.toList(), + namedArguments, + typeArguments, + ); /// Returns an expression accessing `.` on this expression. - Expression property(String name) => BinaryExpression._( - this, - LiteralExpression._(name), - '.', - addSpace: false, - ); + Expression property(String name) => + BinaryExpression._(this, LiteralExpression._(name), '.', addSpace: false); /// Returns an expression accessing `..` on this expression. Expression cascade(String name) => BinaryExpression._( - this, - LiteralExpression._(name), - '..', - addSpace: false, - ); + this, + LiteralExpression._(name), + '..', + addSpace: false, + ); /// Returns an expression accessing `?.` on this expression. Expression nullSafeProperty(String name) => BinaryExpression._( - this, - LiteralExpression._(name), - '?.', - addSpace: false, - ); + this, + LiteralExpression._(name), + '?.', + addSpace: false, + ); /// Applies the null check operator on this expression, returning `this` `!`. /// /// Please note that this is only valid when emitting code with the null /// safety syntax enabled. Expression get nullChecked => BinaryExpression._( - this, - const LiteralExpression._('!'), - '', - addSpace: false, - ); + this, + const LiteralExpression._('!'), + '', + addSpace: false, + ); /// This expression preceded by `return`. - Expression get returned => BinaryExpression._( - const LiteralExpression._('return'), - this, - '', - ); + Expression get returned => + BinaryExpression._(const LiteralExpression._('return'), this, ''); /// This expression preceded by the spread operator `...`. Expression get spread => BinaryExpression._( - const LiteralExpression._('...'), - this, - '', - addSpace: false, - ); + const LiteralExpression._('...'), + this, + '', + addSpace: false, + ); /// This expression preceded by the null safe spread operator `?...`. Expression get nullSafeSpread => BinaryExpression._( - const LiteralExpression._('...?'), - this, - '', - addSpace: false, - ); + const LiteralExpression._('...?'), + this, + '', + addSpace: false, + ); /// This expression preceded by `throw`. - Expression get thrown => BinaryExpression._( - const LiteralExpression._('throw'), - this, - '', - ); + Expression get thrown => + BinaryExpression._(const LiteralExpression._('throw'), this, ''); /// May be overridden to support other types implementing [Expression]. @visibleForOverriding @@ -443,49 +371,63 @@ abstract class Expression implements Spec { /// Returns `const {variableName}`, or `const {type} {variableName}`. Expression declareConst(String variableName, {Reference? type}) => BinaryExpression._( - const LiteralExpression._('const'), - type == null - ? LiteralExpression._(variableName) - : _typedVar(variableName, type), - '', - isConst: true); + const LiteralExpression._('const'), + type == null + ? LiteralExpression._(variableName) + : _typedVar(variableName, type), + '', + isConst: true, + ); /// Declare a final variable named [variableName]. /// /// Returns `final {variableName}`, or `final {type} {variableName}`. /// If [late] is true the declaration is prefixed with `late`. -Expression declareFinal(String variableName, - {Reference? type, bool late = false}) => - _late( - late, - type == null - ? LiteralExpression._('final $variableName') - : BinaryExpression._(const LiteralExpression._('final'), - _typedVar(variableName, type), '')); +Expression declareFinal( + String variableName, { + Reference? type, + bool late = false, +}) => _late( + late, + type == null + ? LiteralExpression._('final $variableName') + : BinaryExpression._( + const LiteralExpression._('final'), + _typedVar(variableName, type), + '', + ), +); /// Declare a variable named [variableName]. /// /// Returns `var {variableName}`, or `{type} {variableName}`. /// If [late] is true the declaration is prefixed with `late`. -Expression declareVar(String variableName, - {Reference? type, bool late = false}) => - _late( - late, - type == null - ? LiteralExpression._('var $variableName') - : _typedVar(variableName, type)); +Expression declareVar( + String variableName, { + Reference? type, + bool late = false, +}) => _late( + late, + type == null + ? LiteralExpression._('var $variableName') + : _typedVar(variableName, type), +); Expression _typedVar(String variableName, Reference type) => BinaryExpression._(type.expression, LiteralExpression._(variableName), ''); -Expression _late(bool late, Expression expression) => late - ? BinaryExpression._(const LiteralExpression._('late'), expression, '') - : expression; +Expression _late(bool late, Expression expression) => + late + ? BinaryExpression._(const LiteralExpression._('late'), expression, '') + : expression; /// Creates `typedef {name} =`. -Code createTypeDef(String name, FunctionType type) => BinaryExpression._( - LiteralExpression._('typedef $name'), type.expression, '=') - .statement; +Code createTypeDef(String name, FunctionType type) => + BinaryExpression._( + LiteralExpression._('typedef $name'), + type.expression, + '=', + ).statement; class ToCodeExpression implements Code { final Expression code; @@ -517,10 +459,14 @@ abstract class ExpressionVisitor implements SpecVisitor { T visitLiteralListExpression(LiteralListExpression expression, [T? context]); T visitLiteralSetExpression(LiteralSetExpression expression, [T? context]); T visitLiteralMapExpression(LiteralMapExpression expression, [T? context]); - T visitLiteralRecordExpression(LiteralRecordExpression expression, - [T? context]); - T visitParenthesizedExpression(ParenthesizedExpression expression, - [T? context]); + T visitLiteralRecordExpression( + LiteralRecordExpression expression, [ + T? context, + ]); + T visitParenthesizedExpression( + ParenthesizedExpression expression, [ + T? context, + ]); } /// Knowledge of how to write valid Dart code from [ExpressionVisitor]. @@ -529,8 +475,10 @@ abstract class ExpressionVisitor implements SpecVisitor { abstract mixin class ExpressionEmitter implements ExpressionVisitor { @override - StringSink visitToCodeExpression(ToCodeExpression expression, - [StringSink? output]) { + StringSink visitToCodeExpression( + ToCodeExpression expression, [ + StringSink? output, + ]) { output ??= StringBuffer(); expression.code.accept(this, output); if (expression.isStatement) { @@ -540,8 +488,10 @@ abstract mixin class ExpressionEmitter } @override - StringSink visitBinaryExpression(BinaryExpression expression, - [StringSink? output]) { + StringSink visitBinaryExpression( + BinaryExpression expression, [ + StringSink? output, + ]) { output ??= StringBuffer(); expression.left.accept(this, output); if (expression.addSpace) { @@ -558,23 +508,29 @@ abstract mixin class ExpressionEmitter } @override - StringSink visitClosureExpression(ClosureExpression expression, - [StringSink? output]) { + StringSink visitClosureExpression( + ClosureExpression expression, [ + StringSink? output, + ]) { output ??= StringBuffer(); return expression.method.accept(this, output); } @override - StringSink visitCodeExpression(CodeExpression expression, - [StringSink? output]) { + StringSink visitCodeExpression( + CodeExpression expression, [ + StringSink? output, + ]) { output ??= StringBuffer(); final visitor = this as CodeVisitor; return expression.code.accept(visitor, output); } @override - StringSink visitInvokeExpression(InvokeExpression expression, - [StringSink? output]) { + StringSink visitInvokeExpression( + InvokeExpression expression, [ + StringSink? output, + ]) { final out = output ??= StringBuffer(); return _writeConstExpression(out, expression.isConst, () { expression.target.accept(this, out); @@ -604,7 +560,8 @@ abstract mixin class ExpressionEmitter ..write(': '); expression.namedArguments[name]!.accept(this, out); }); - final argumentCount = expression.positionalArguments.length + + final argumentCount = + expression.positionalArguments.length + expression.namedArguments.length; if (argumentCount > 1) { out.write(', '); @@ -614,8 +571,10 @@ abstract mixin class ExpressionEmitter } @override - StringSink visitLiteralExpression(LiteralExpression expression, - [StringSink? output]) { + StringSink visitLiteralExpression( + LiteralExpression expression, [ + StringSink? output, + ]) { output ??= StringBuffer(); return output..write(expression.literal); } @@ -731,10 +690,13 @@ abstract mixin class ExpressionEmitter out.write(','); } visitAll>( - expression.namedFieldValues.entries, out, (entry) { - out.write('${entry.key}: '); - _acceptLiteral(entry.value, out); - }); + expression.namedFieldValues.entries, + out, + (entry) { + out.write('${entry.key}: '); + _acceptLiteral(entry.value, out); + }, + ); return out..write(')'); }); } @@ -756,10 +718,7 @@ abstract mixin class ExpressionEmitter /// /// This allows constant expressions to omit the `const` keyword if they /// are already within a constant expression. - void startConstCode( - bool isConst, - Null Function() visit, - ) { + void startConstCode(bool isConst, Null Function() visit) { final previousConstContext = _withInConstExpression; if (isConst) { _withInConstExpression = true; diff --git a/pkgs/code_builder/lib/src/specs/expression/invoke.dart b/pkgs/code_builder/lib/src/specs/expression/invoke.dart index f54dc0ecd..ff1f151e9 100644 --- a/pkgs/code_builder/lib/src/specs/expression/invoke.dart +++ b/pkgs/code_builder/lib/src/specs/expression/invoke.dart @@ -28,9 +28,9 @@ class InvokeExpression extends Expression { this.positionalArguments, this.namedArguments, this.typeArguments, - ) : name = null, - type = null, - isConst = false; + ) : name = null, + type = null, + isConst = false; const InvokeExpression.newOf( this.target, @@ -38,8 +38,8 @@ class InvokeExpression extends Expression { this.namedArguments = const {}, this.typeArguments = const [], this.name, - ]) : type = InvokeExpressionType.newInstance, - isConst = false; + ]) : type = InvokeExpressionType.newInstance, + isConst = false; const InvokeExpression.constOf( this.target, @@ -47,8 +47,8 @@ class InvokeExpression extends Expression { this.namedArguments = const {}, this.typeArguments = const [], this.name, - ]) : type = InvokeExpressionType.constInstance, - isConst = true; + ]) : type = InvokeExpressionType.constInstance, + isConst = true; @override R accept(ExpressionVisitor visitor, [R? context]) => @@ -59,7 +59,4 @@ class InvokeExpression extends Expression { '${type ?? ''} $target($positionalArguments, $namedArguments)'; } -enum InvokeExpressionType { - newInstance, - constInstance, -} +enum InvokeExpressionType { newInstance, constInstance } diff --git a/pkgs/code_builder/lib/src/specs/expression/literal.dart b/pkgs/code_builder/lib/src/specs/expression/literal.dart index ced6cf90f..d4b687a6d 100644 --- a/pkgs/code_builder/lib/src/specs/expression/literal.dart +++ b/pkgs/code_builder/lib/src/specs/expression/literal.dart @@ -69,14 +69,16 @@ Expression literalSpread() => LiteralSpreadExpression._(false); Expression literalNullSafeSpread() => LiteralSpreadExpression._(true); /// Creates a literal list expression from [values]. -LiteralListExpression literalList(Iterable values, - [Reference? type]) => - LiteralListExpression._(false, values.toList(), type); +LiteralListExpression literalList( + Iterable values, [ + Reference? type, +]) => LiteralListExpression._(false, values.toList(), type); /// Creates a literal `const` list expression from [values]. -LiteralListExpression literalConstList(List values, - [Reference? type]) => - LiteralListExpression._(true, values, type); +LiteralListExpression literalConstList( + List values, [ + Reference? type, +]) => LiteralListExpression._(true, values, type); /// Creates a literal set expression from [values]. LiteralSetExpression literalSet(Iterable values, [Reference? type]) => @@ -91,28 +93,28 @@ LiteralMapExpression literalMap( Map values, [ Reference? keyType, Reference? valueType, -]) => - LiteralMapExpression._(false, values, keyType, valueType); +]) => LiteralMapExpression._(false, values, keyType, valueType); /// Create a literal `const` map expression from [values]. LiteralMapExpression literalConstMap( Map values, [ Reference? keyType, Reference? valueType, -]) => - LiteralMapExpression._(true, values, keyType, valueType); +]) => LiteralMapExpression._(true, values, keyType, valueType); /// Create a literal record expression from [positionalFieldValues] and /// [namedFieldValues]. -LiteralRecordExpression literalRecord(List positionalFieldValues, - Map namedFieldValues) => - LiteralRecordExpression._(false, positionalFieldValues, namedFieldValues); +LiteralRecordExpression literalRecord( + List positionalFieldValues, + Map namedFieldValues, +) => LiteralRecordExpression._(false, positionalFieldValues, namedFieldValues); /// Create a literal `const` record expression from [positionalFieldValues] and /// [namedFieldValues]. -LiteralRecordExpression literalConstRecord(List positionalFieldValues, - Map namedFieldValues) => - LiteralRecordExpression._(true, positionalFieldValues, namedFieldValues); +LiteralRecordExpression literalConstRecord( + List positionalFieldValues, + Map namedFieldValues, +) => LiteralRecordExpression._(true, positionalFieldValues, namedFieldValues); /// Represents a literal value in Dart source code. /// @@ -139,7 +141,7 @@ class LiteralExpression extends Expression { class LiteralSpreadExpression extends LiteralExpression { LiteralSpreadExpression._(bool nullAware) - : super._('...${nullAware ? '?' : ''}'); + : super._('...${nullAware ? '?' : ''}'); } class LiteralListExpression extends Expression { @@ -203,7 +205,10 @@ class LiteralRecordExpression extends Expression { final Map namedFieldValues; const LiteralRecordExpression._( - this.isConst, this.positionalFieldValues, this.namedFieldValues); + this.isConst, + this.positionalFieldValues, + this.namedFieldValues, + ); @override R accept(ExpressionVisitor visitor, [R? context]) => @@ -211,8 +216,11 @@ class LiteralRecordExpression extends Expression { @override String toString() { - final allFields = positionalFieldValues.map((v) => v.toString()).followedBy( - namedFieldValues.entries.map((e) => '${e.key}: ${e.value}')); + final allFields = positionalFieldValues + .map((v) => v.toString()) + .followedBy( + namedFieldValues.entries.map((e) => '${e.key}: ${e.value}'), + ); return '(${allFields.join(', ')})'; } } diff --git a/pkgs/code_builder/lib/src/specs/extension.dart b/pkgs/code_builder/lib/src/specs/extension.dart index 395994fc7..ba7ee00a5 100644 --- a/pkgs/code_builder/lib/src/specs/extension.dart +++ b/pkgs/code_builder/lib/src/specs/extension.dart @@ -45,10 +45,7 @@ abstract class Extension extends Object String? get name; @override - R accept( - SpecVisitor visitor, [ - R? context, - ]) => + R accept(SpecVisitor visitor, [R? context]) => visitor.visitExtension(this, context); } diff --git a/pkgs/code_builder/lib/src/specs/extension.g.dart b/pkgs/code_builder/lib/src/specs/extension.g.dart index 83de17614..5782c3da7 100644 --- a/pkgs/code_builder/lib/src/specs/extension.g.dart +++ b/pkgs/code_builder/lib/src/specs/extension.g.dart @@ -25,17 +25,20 @@ class _$Extension extends Extension { factory _$Extension([void Function(ExtensionBuilder)? updates]) => (new ExtensionBuilder()..update(updates)).build() as _$Extension; - _$Extension._( - {required this.annotations, - required this.docs, - this.on, - required this.types, - required this.methods, - required this.fields, - this.name}) - : super._() { + _$Extension._({ + required this.annotations, + required this.docs, + this.on, + required this.types, + required this.methods, + required this.fields, + this.name, + }) : super._() { BuiltValueNullFieldError.checkNotNull( - annotations, r'Extension', 'annotations'); + annotations, + r'Extension', + 'annotations', + ); BuiltValueNullFieldError.checkNotNull(docs, r'Extension', 'docs'); BuiltValueNullFieldError.checkNotNull(types, r'Extension', 'types'); BuiltValueNullFieldError.checkNotNull(methods, r'Extension', 'methods'); @@ -211,15 +214,17 @@ class _$ExtensionBuilder extends ExtensionBuilder { _$Extension _build() { _$Extension _$result; try { - _$result = _$v ?? + _$result = + _$v ?? new _$Extension._( - annotations: annotations.build(), - docs: docs.build(), - on: on, - types: types.build(), - methods: methods.build(), - fields: fields.build(), - name: name); + annotations: annotations.build(), + docs: docs.build(), + on: on, + types: types.build(), + methods: methods.build(), + fields: fields.build(), + name: name, + ); } catch (_) { late String _$failedField; try { @@ -236,7 +241,10 @@ class _$ExtensionBuilder extends ExtensionBuilder { fields.build(); } catch (e) { throw new BuiltValueNestedFieldError( - r'Extension', _$failedField, e.toString()); + r'Extension', + _$failedField, + e.toString(), + ); } rethrow; } diff --git a/pkgs/code_builder/lib/src/specs/extension_type.dart b/pkgs/code_builder/lib/src/specs/extension_type.dart index ec3bd3355..2d5196a87 100644 --- a/pkgs/code_builder/lib/src/specs/extension_type.dart +++ b/pkgs/code_builder/lib/src/specs/extension_type.dart @@ -57,10 +57,7 @@ abstract class ExtensionType extends Object BuiltList get methods; @override - R accept( - SpecVisitor visitor, [ - R? context, - ]) => + R accept(SpecVisitor visitor, [R? context]) => visitor.visitExtensionType(this, context); } @@ -109,9 +106,9 @@ abstract class RepresentationDeclaration extends Object with HasAnnotations, HasDartDocs implements Built { - factory RepresentationDeclaration( - [void Function(RepresentationDeclarationBuilder)? updates]) = - _$RepresentationDeclaration; + factory RepresentationDeclaration([ + void Function(RepresentationDeclarationBuilder)? updates, + ]) = _$RepresentationDeclaration; RepresentationDeclaration._(); diff --git a/pkgs/code_builder/lib/src/specs/extension_type.g.dart b/pkgs/code_builder/lib/src/specs/extension_type.g.dart index 576984032..17443ce54 100644 --- a/pkgs/code_builder/lib/src/specs/extension_type.g.dart +++ b/pkgs/code_builder/lib/src/specs/extension_type.g.dart @@ -33,34 +33,52 @@ class _$ExtensionType extends ExtensionType { factory _$ExtensionType([void Function(ExtensionTypeBuilder)? updates]) => (new ExtensionTypeBuilder()..update(updates)).build() as _$ExtensionType; - _$ExtensionType._( - {required this.annotations, - required this.docs, - required this.constant, - required this.name, - required this.types, - required this.primaryConstructorName, - required this.representationDeclaration, - required this.implements, - required this.constructors, - required this.fields, - required this.methods}) - : super._() { + _$ExtensionType._({ + required this.annotations, + required this.docs, + required this.constant, + required this.name, + required this.types, + required this.primaryConstructorName, + required this.representationDeclaration, + required this.implements, + required this.constructors, + required this.fields, + required this.methods, + }) : super._() { BuiltValueNullFieldError.checkNotNull( - annotations, r'ExtensionType', 'annotations'); + annotations, + r'ExtensionType', + 'annotations', + ); BuiltValueNullFieldError.checkNotNull(docs, r'ExtensionType', 'docs'); BuiltValueNullFieldError.checkNotNull( - constant, r'ExtensionType', 'constant'); + constant, + r'ExtensionType', + 'constant', + ); BuiltValueNullFieldError.checkNotNull(name, r'ExtensionType', 'name'); BuiltValueNullFieldError.checkNotNull(types, r'ExtensionType', 'types'); BuiltValueNullFieldError.checkNotNull( - primaryConstructorName, r'ExtensionType', 'primaryConstructorName'); - BuiltValueNullFieldError.checkNotNull(representationDeclaration, - r'ExtensionType', 'representationDeclaration'); + primaryConstructorName, + r'ExtensionType', + 'primaryConstructorName', + ); BuiltValueNullFieldError.checkNotNull( - implements, r'ExtensionType', 'implements'); + representationDeclaration, + r'ExtensionType', + 'representationDeclaration', + ); BuiltValueNullFieldError.checkNotNull( - constructors, r'ExtensionType', 'constructors'); + implements, + r'ExtensionType', + 'implements', + ); + BuiltValueNullFieldError.checkNotNull( + constructors, + r'ExtensionType', + 'constructors', + ); BuiltValueNullFieldError.checkNotNull(fields, r'ExtensionType', 'fields'); BuiltValueNullFieldError.checkNotNull(methods, r'ExtensionType', 'methods'); } @@ -209,7 +227,8 @@ class _$ExtensionTypeBuilder extends ExtensionTypeBuilder { @override set representationDeclaration( - RepresentationDeclaration? representationDeclaration) { + RepresentationDeclaration? representationDeclaration, + ) { _$this; super.representationDeclaration = representationDeclaration; } @@ -300,27 +319,37 @@ class _$ExtensionTypeBuilder extends ExtensionTypeBuilder { _$ExtensionType _build() { _$ExtensionType _$result; try { - _$result = _$v ?? + _$result = + _$v ?? new _$ExtensionType._( - annotations: annotations.build(), - docs: docs.build(), - constant: BuiltValueNullFieldError.checkNotNull( - constant, r'ExtensionType', 'constant'), - name: BuiltValueNullFieldError.checkNotNull( - name, r'ExtensionType', 'name'), - types: types.build(), - primaryConstructorName: BuiltValueNullFieldError.checkNotNull( - primaryConstructorName, - r'ExtensionType', - 'primaryConstructorName'), - representationDeclaration: BuiltValueNullFieldError.checkNotNull( - representationDeclaration, - r'ExtensionType', - 'representationDeclaration'), - implements: implements.build(), - constructors: constructors.build(), - fields: fields.build(), - methods: methods.build()); + annotations: annotations.build(), + docs: docs.build(), + constant: BuiltValueNullFieldError.checkNotNull( + constant, + r'ExtensionType', + 'constant', + ), + name: BuiltValueNullFieldError.checkNotNull( + name, + r'ExtensionType', + 'name', + ), + types: types.build(), + primaryConstructorName: BuiltValueNullFieldError.checkNotNull( + primaryConstructorName, + r'ExtensionType', + 'primaryConstructorName', + ), + representationDeclaration: BuiltValueNullFieldError.checkNotNull( + representationDeclaration, + r'ExtensionType', + 'representationDeclaration', + ), + implements: implements.build(), + constructors: constructors.build(), + fields: fields.build(), + methods: methods.build(), + ); } catch (_) { late String _$failedField; try { @@ -342,7 +371,10 @@ class _$ExtensionTypeBuilder extends ExtensionTypeBuilder { methods.build(); } catch (e) { throw new BuiltValueNestedFieldError( - r'ExtensionType', _$failedField, e.toString()); + r'ExtensionType', + _$failedField, + e.toString(), + ); } rethrow; } @@ -361,31 +393,44 @@ class _$RepresentationDeclaration extends RepresentationDeclaration { @override final String name; - factory _$RepresentationDeclaration( - [void Function(RepresentationDeclarationBuilder)? updates]) => + factory _$RepresentationDeclaration([ + void Function(RepresentationDeclarationBuilder)? updates, + ]) => (new RepresentationDeclarationBuilder()..update(updates)).build() as _$RepresentationDeclaration; - _$RepresentationDeclaration._( - {required this.annotations, - required this.docs, - required this.declaredRepresentationType, - required this.name}) - : super._() { + _$RepresentationDeclaration._({ + required this.annotations, + required this.docs, + required this.declaredRepresentationType, + required this.name, + }) : super._() { + BuiltValueNullFieldError.checkNotNull( + annotations, + r'RepresentationDeclaration', + 'annotations', + ); BuiltValueNullFieldError.checkNotNull( - annotations, r'RepresentationDeclaration', 'annotations'); + docs, + r'RepresentationDeclaration', + 'docs', + ); BuiltValueNullFieldError.checkNotNull( - docs, r'RepresentationDeclaration', 'docs'); - BuiltValueNullFieldError.checkNotNull(declaredRepresentationType, - r'RepresentationDeclaration', 'declaredRepresentationType'); + declaredRepresentationType, + r'RepresentationDeclaration', + 'declaredRepresentationType', + ); BuiltValueNullFieldError.checkNotNull( - name, r'RepresentationDeclaration', 'name'); + name, + r'RepresentationDeclaration', + 'name', + ); } @override RepresentationDeclaration rebuild( - void Function(RepresentationDeclarationBuilder) updates) => - (toBuilder()..update(updates)).build(); + void Function(RepresentationDeclarationBuilder) updates, + ) => (toBuilder()..update(updates)).build(); @override _$RepresentationDeclarationBuilder toBuilder() => @@ -506,16 +551,22 @@ class _$RepresentationDeclarationBuilder _$RepresentationDeclaration _build() { _$RepresentationDeclaration _$result; try { - _$result = _$v ?? + _$result = + _$v ?? new _$RepresentationDeclaration._( - annotations: annotations.build(), - docs: docs.build(), - declaredRepresentationType: BuiltValueNullFieldError.checkNotNull( - declaredRepresentationType, - r'RepresentationDeclaration', - 'declaredRepresentationType'), - name: BuiltValueNullFieldError.checkNotNull( - name, r'RepresentationDeclaration', 'name')); + annotations: annotations.build(), + docs: docs.build(), + declaredRepresentationType: BuiltValueNullFieldError.checkNotNull( + declaredRepresentationType, + r'RepresentationDeclaration', + 'declaredRepresentationType', + ), + name: BuiltValueNullFieldError.checkNotNull( + name, + r'RepresentationDeclaration', + 'name', + ), + ); } catch (_) { late String _$failedField; try { @@ -525,7 +576,10 @@ class _$RepresentationDeclarationBuilder docs.build(); } catch (e) { throw new BuiltValueNestedFieldError( - r'RepresentationDeclaration', _$failedField, e.toString()); + r'RepresentationDeclaration', + _$failedField, + e.toString(), + ); } rethrow; } diff --git a/pkgs/code_builder/lib/src/specs/field.dart b/pkgs/code_builder/lib/src/specs/field.dart index 7930bf6fa..bb77dbd15 100644 --- a/pkgs/code_builder/lib/src/specs/field.dart +++ b/pkgs/code_builder/lib/src/specs/field.dart @@ -52,18 +52,11 @@ abstract class Field extends Object FieldModifier get modifier; @override - R accept( - SpecVisitor visitor, [ - R? context, - ]) => + R accept(SpecVisitor visitor, [R? context]) => visitor.visitField(this, context); } -enum FieldModifier { - var$, - final$, - constant, -} +enum FieldModifier { var$, final$, constant } abstract class FieldBuilder extends Object with HasAnnotationsBuilder, HasDartDocsBuilder diff --git a/pkgs/code_builder/lib/src/specs/field.g.dart b/pkgs/code_builder/lib/src/specs/field.g.dart index d15f1c7dc..15913b891 100644 --- a/pkgs/code_builder/lib/src/specs/field.g.dart +++ b/pkgs/code_builder/lib/src/specs/field.g.dart @@ -29,17 +29,17 @@ class _$Field extends Field { factory _$Field([void Function(FieldBuilder)? updates]) => (new FieldBuilder()..update(updates)).build() as _$Field; - _$Field._( - {required this.annotations, - required this.docs, - this.assignment, - required this.static, - required this.late, - required this.external, - required this.name, - this.type, - required this.modifier}) - : super._() { + _$Field._({ + required this.annotations, + required this.docs, + this.assignment, + required this.static, + required this.late, + required this.external, + required this.name, + this.type, + required this.modifier, + }) : super._() { BuiltValueNullFieldError.checkNotNull(annotations, r'Field', 'annotations'); BuiltValueNullFieldError.checkNotNull(docs, r'Field', 'docs'); BuiltValueNullFieldError.checkNotNull(static, r'Field', 'static'); @@ -250,22 +250,31 @@ class _$FieldBuilder extends FieldBuilder { _$Field _build() { _$Field _$result; try { - _$result = _$v ?? + _$result = + _$v ?? new _$Field._( - annotations: annotations.build(), - docs: docs.build(), - assignment: assignment, - static: BuiltValueNullFieldError.checkNotNull( - static, r'Field', 'static'), - late: - BuiltValueNullFieldError.checkNotNull(late, r'Field', 'late'), - external: BuiltValueNullFieldError.checkNotNull( - external, r'Field', 'external'), - name: - BuiltValueNullFieldError.checkNotNull(name, r'Field', 'name'), - type: type, - modifier: BuiltValueNullFieldError.checkNotNull( - modifier, r'Field', 'modifier')); + annotations: annotations.build(), + docs: docs.build(), + assignment: assignment, + static: BuiltValueNullFieldError.checkNotNull( + static, + r'Field', + 'static', + ), + late: BuiltValueNullFieldError.checkNotNull(late, r'Field', 'late'), + external: BuiltValueNullFieldError.checkNotNull( + external, + r'Field', + 'external', + ), + name: BuiltValueNullFieldError.checkNotNull(name, r'Field', 'name'), + type: type, + modifier: BuiltValueNullFieldError.checkNotNull( + modifier, + r'Field', + 'modifier', + ), + ); } catch (_) { late String _$failedField; try { @@ -275,7 +284,10 @@ class _$FieldBuilder extends FieldBuilder { docs.build(); } catch (e) { throw new BuiltValueNestedFieldError( - r'Field', _$failedField, e.toString()); + r'Field', + _$failedField, + e.toString(), + ); } rethrow; } diff --git a/pkgs/code_builder/lib/src/specs/library.dart b/pkgs/code_builder/lib/src/specs/library.dart index bbfbf3f86..619c4a819 100644 --- a/pkgs/code_builder/lib/src/specs/library.dart +++ b/pkgs/code_builder/lib/src/specs/library.dart @@ -49,10 +49,7 @@ abstract class Library String? get name; @override - R accept( - SpecVisitor visitor, [ - R? context, - ]) => + R accept(SpecVisitor visitor, [R? context]) => visitor.visitLibrary(this, context); } diff --git a/pkgs/code_builder/lib/src/specs/library.g.dart b/pkgs/code_builder/lib/src/specs/library.g.dart index 63cfc200b..36e946302 100644 --- a/pkgs/code_builder/lib/src/specs/library.g.dart +++ b/pkgs/code_builder/lib/src/specs/library.g.dart @@ -27,24 +27,30 @@ class _$Library extends Library { factory _$Library([void Function(LibraryBuilder)? updates]) => (new LibraryBuilder()..update(updates)).build() as _$Library; - _$Library._( - {required this.annotations, - required this.docs, - required this.directives, - required this.body, - required this.comments, - this.generatedByComment, - required this.ignoreForFile, - this.name}) - : super._() { + _$Library._({ + required this.annotations, + required this.docs, + required this.directives, + required this.body, + required this.comments, + this.generatedByComment, + required this.ignoreForFile, + this.name, + }) : super._() { BuiltValueNullFieldError.checkNotNull( - annotations, r'Library', 'annotations'); + annotations, + r'Library', + 'annotations', + ); BuiltValueNullFieldError.checkNotNull(docs, r'Library', 'docs'); BuiltValueNullFieldError.checkNotNull(directives, r'Library', 'directives'); BuiltValueNullFieldError.checkNotNull(body, r'Library', 'body'); BuiltValueNullFieldError.checkNotNull(comments, r'Library', 'comments'); BuiltValueNullFieldError.checkNotNull( - ignoreForFile, r'Library', 'ignoreForFile'); + ignoreForFile, + r'Library', + 'ignoreForFile', + ); } @override @@ -232,16 +238,18 @@ class _$LibraryBuilder extends LibraryBuilder { _$Library _build() { _$Library _$result; try { - _$result = _$v ?? + _$result = + _$v ?? new _$Library._( - annotations: annotations.build(), - docs: docs.build(), - directives: directives.build(), - body: body.build(), - comments: comments.build(), - generatedByComment: generatedByComment, - ignoreForFile: ignoreForFile.build(), - name: name); + annotations: annotations.build(), + docs: docs.build(), + directives: directives.build(), + body: body.build(), + comments: comments.build(), + generatedByComment: generatedByComment, + ignoreForFile: ignoreForFile.build(), + name: name, + ); } catch (_) { late String _$failedField; try { @@ -260,7 +268,10 @@ class _$LibraryBuilder extends LibraryBuilder { ignoreForFile.build(); } catch (e) { throw new BuiltValueNestedFieldError( - r'Library', _$failedField, e.toString()); + r'Library', + _$failedField, + e.toString(), + ); } rethrow; } diff --git a/pkgs/code_builder/lib/src/specs/method.dart b/pkgs/code_builder/lib/src/specs/method.dart index 2c0a645dc..08d6331d6 100644 --- a/pkgs/code_builder/lib/src/specs/method.dart +++ b/pkgs/code_builder/lib/src/specs/method.dart @@ -80,10 +80,7 @@ abstract class Method extends Object Reference? get returns; @override - R accept( - SpecVisitor visitor, [ - R? context, - ]) => + R accept(SpecVisitor visitor, [R? context]) => visitor.visitMethod(this, context); /// This method as a closure. @@ -148,16 +145,9 @@ abstract class MethodBuilder extends Object Reference? returns; } -enum MethodType { - getter, - setter, -} +enum MethodType { getter, setter } -enum MethodModifier { - async, - asyncStar, - syncStar, -} +enum MethodModifier { async, asyncStar, syncStar } abstract class Parameter extends Object with HasAnnotations, HasGenerics, HasDartDocs diff --git a/pkgs/code_builder/lib/src/specs/method.g.dart b/pkgs/code_builder/lib/src/specs/method.g.dart index 214f6b214..ecdf9023a 100644 --- a/pkgs/code_builder/lib/src/specs/method.g.dart +++ b/pkgs/code_builder/lib/src/specs/method.g.dart @@ -37,29 +37,38 @@ class _$Method extends Method { factory _$Method([void Function(MethodBuilder)? updates]) => (new MethodBuilder()..update(updates)).build() as _$Method; - _$Method._( - {required this.annotations, - required this.docs, - required this.types, - required this.optionalParameters, - required this.requiredParameters, - this.body, - required this.external, - this.lambda, - required this.static, - this.name, - this.type, - this.modifier, - this.returns}) - : super._() { + _$Method._({ + required this.annotations, + required this.docs, + required this.types, + required this.optionalParameters, + required this.requiredParameters, + this.body, + required this.external, + this.lambda, + required this.static, + this.name, + this.type, + this.modifier, + this.returns, + }) : super._() { BuiltValueNullFieldError.checkNotNull( - annotations, r'Method', 'annotations'); + annotations, + r'Method', + 'annotations', + ); BuiltValueNullFieldError.checkNotNull(docs, r'Method', 'docs'); BuiltValueNullFieldError.checkNotNull(types, r'Method', 'types'); BuiltValueNullFieldError.checkNotNull( - optionalParameters, r'Method', 'optionalParameters'); + optionalParameters, + r'Method', + 'optionalParameters', + ); BuiltValueNullFieldError.checkNotNull( - requiredParameters, r'Method', 'requiredParameters'); + requiredParameters, + r'Method', + 'requiredParameters', + ); BuiltValueNullFieldError.checkNotNull(external, r'Method', 'external'); BuiltValueNullFieldError.checkNotNull(static, r'Method', 'static'); } @@ -329,23 +338,31 @@ class _$MethodBuilder extends MethodBuilder { _$Method _build() { _$Method _$result; try { - _$result = _$v ?? + _$result = + _$v ?? new _$Method._( - annotations: annotations.build(), - docs: docs.build(), - types: types.build(), - optionalParameters: optionalParameters.build(), - requiredParameters: requiredParameters.build(), - body: body, - external: BuiltValueNullFieldError.checkNotNull( - external, r'Method', 'external'), - lambda: lambda, - static: BuiltValueNullFieldError.checkNotNull( - static, r'Method', 'static'), - name: name, - type: type, - modifier: modifier, - returns: returns); + annotations: annotations.build(), + docs: docs.build(), + types: types.build(), + optionalParameters: optionalParameters.build(), + requiredParameters: requiredParameters.build(), + body: body, + external: BuiltValueNullFieldError.checkNotNull( + external, + r'Method', + 'external', + ), + lambda: lambda, + static: BuiltValueNullFieldError.checkNotNull( + static, + r'Method', + 'static', + ), + name: name, + type: type, + modifier: modifier, + returns: returns, + ); } catch (_) { late String _$failedField; try { @@ -361,7 +378,10 @@ class _$MethodBuilder extends MethodBuilder { requiredParameters.build(); } catch (e) { throw new BuiltValueNestedFieldError( - r'Method', _$failedField, e.toString()); + r'Method', + _$failedField, + e.toString(), + ); } rethrow; } @@ -397,25 +417,28 @@ class _$Parameter extends Parameter { factory _$Parameter([void Function(ParameterBuilder)? updates]) => (new ParameterBuilder()..update(updates)).build() as _$Parameter; - _$Parameter._( - {this.defaultTo, - required this.name, - required this.named, - required this.toThis, - required this.toSuper, - required this.annotations, - required this.docs, - required this.types, - this.type, - required this.required, - required this.covariant}) - : super._() { + _$Parameter._({ + this.defaultTo, + required this.name, + required this.named, + required this.toThis, + required this.toSuper, + required this.annotations, + required this.docs, + required this.types, + this.type, + required this.required, + required this.covariant, + }) : super._() { BuiltValueNullFieldError.checkNotNull(name, r'Parameter', 'name'); BuiltValueNullFieldError.checkNotNull(named, r'Parameter', 'named'); BuiltValueNullFieldError.checkNotNull(toThis, r'Parameter', 'toThis'); BuiltValueNullFieldError.checkNotNull(toSuper, r'Parameter', 'toSuper'); BuiltValueNullFieldError.checkNotNull( - annotations, r'Parameter', 'annotations'); + annotations, + r'Parameter', + 'annotations', + ); BuiltValueNullFieldError.checkNotNull(docs, r'Parameter', 'docs'); BuiltValueNullFieldError.checkNotNull(types, r'Parameter', 'types'); BuiltValueNullFieldError.checkNotNull(required, r'Parameter', 'required'); @@ -655,25 +678,45 @@ class _$ParameterBuilder extends ParameterBuilder { _$Parameter _build() { _$Parameter _$result; try { - _$result = _$v ?? + _$result = + _$v ?? new _$Parameter._( - defaultTo: defaultTo, - name: BuiltValueNullFieldError.checkNotNull( - name, r'Parameter', 'name'), - named: BuiltValueNullFieldError.checkNotNull( - named, r'Parameter', 'named'), - toThis: BuiltValueNullFieldError.checkNotNull( - toThis, r'Parameter', 'toThis'), - toSuper: BuiltValueNullFieldError.checkNotNull( - toSuper, r'Parameter', 'toSuper'), - annotations: annotations.build(), - docs: docs.build(), - types: types.build(), - type: type, - required: BuiltValueNullFieldError.checkNotNull( - required, r'Parameter', 'required'), - covariant: BuiltValueNullFieldError.checkNotNull( - covariant, r'Parameter', 'covariant')); + defaultTo: defaultTo, + name: BuiltValueNullFieldError.checkNotNull( + name, + r'Parameter', + 'name', + ), + named: BuiltValueNullFieldError.checkNotNull( + named, + r'Parameter', + 'named', + ), + toThis: BuiltValueNullFieldError.checkNotNull( + toThis, + r'Parameter', + 'toThis', + ), + toSuper: BuiltValueNullFieldError.checkNotNull( + toSuper, + r'Parameter', + 'toSuper', + ), + annotations: annotations.build(), + docs: docs.build(), + types: types.build(), + type: type, + required: BuiltValueNullFieldError.checkNotNull( + required, + r'Parameter', + 'required', + ), + covariant: BuiltValueNullFieldError.checkNotNull( + covariant, + r'Parameter', + 'covariant', + ), + ); } catch (_) { late String _$failedField; try { @@ -685,7 +728,10 @@ class _$ParameterBuilder extends ParameterBuilder { types.build(); } catch (e) { throw new BuiltValueNestedFieldError( - r'Parameter', _$failedField, e.toString()); + r'Parameter', + _$failedField, + e.toString(), + ); } rethrow; } diff --git a/pkgs/code_builder/lib/src/specs/mixin.dart b/pkgs/code_builder/lib/src/specs/mixin.dart index e666bddaa..e60735788 100644 --- a/pkgs/code_builder/lib/src/specs/mixin.dart +++ b/pkgs/code_builder/lib/src/specs/mixin.dart @@ -49,10 +49,7 @@ abstract class Mixin extends Object String get name; @override - R accept( - SpecVisitor visitor, [ - R? context, - ]) => + R accept(SpecVisitor visitor, [R? context]) => visitor.visitMixin(this, context); } diff --git a/pkgs/code_builder/lib/src/specs/mixin.g.dart b/pkgs/code_builder/lib/src/specs/mixin.g.dart index 28c7356c4..e84a379fc 100644 --- a/pkgs/code_builder/lib/src/specs/mixin.g.dart +++ b/pkgs/code_builder/lib/src/specs/mixin.g.dart @@ -29,17 +29,17 @@ class _$Mixin extends Mixin { factory _$Mixin([void Function(MixinBuilder)? updates]) => (new MixinBuilder()..update(updates)).build() as _$Mixin; - _$Mixin._( - {required this.base, - required this.annotations, - required this.docs, - this.on, - required this.implements, - required this.types, - required this.methods, - required this.fields, - required this.name}) - : super._() { + _$Mixin._({ + required this.base, + required this.annotations, + required this.docs, + this.on, + required this.implements, + required this.types, + required this.methods, + required this.fields, + required this.name, + }) : super._() { BuiltValueNullFieldError.checkNotNull(base, r'Mixin', 'base'); BuiltValueNullFieldError.checkNotNull(annotations, r'Mixin', 'annotations'); BuiltValueNullFieldError.checkNotNull(docs, r'Mixin', 'docs'); @@ -251,19 +251,19 @@ class _$MixinBuilder extends MixinBuilder { _$Mixin _build() { _$Mixin _$result; try { - _$result = _$v ?? + _$result = + _$v ?? new _$Mixin._( - base: - BuiltValueNullFieldError.checkNotNull(base, r'Mixin', 'base'), - annotations: annotations.build(), - docs: docs.build(), - on: on, - implements: implements.build(), - types: types.build(), - methods: methods.build(), - fields: fields.build(), - name: BuiltValueNullFieldError.checkNotNull( - name, r'Mixin', 'name')); + base: BuiltValueNullFieldError.checkNotNull(base, r'Mixin', 'base'), + annotations: annotations.build(), + docs: docs.build(), + on: on, + implements: implements.build(), + types: types.build(), + methods: methods.build(), + fields: fields.build(), + name: BuiltValueNullFieldError.checkNotNull(name, r'Mixin', 'name'), + ); } catch (_) { late String _$failedField; try { @@ -282,7 +282,10 @@ class _$MixinBuilder extends MixinBuilder { fields.build(); } catch (e) { throw new BuiltValueNestedFieldError( - r'Mixin', _$failedField, e.toString()); + r'Mixin', + _$failedField, + e.toString(), + ); } rethrow; } diff --git a/pkgs/code_builder/lib/src/specs/reference.dart b/pkgs/code_builder/lib/src/specs/reference.dart index 06032ad3c..40a3db711 100644 --- a/pkgs/code_builder/lib/src/specs/reference.dart +++ b/pkgs/code_builder/lib/src/specs/reference.dart @@ -35,10 +35,7 @@ class Reference extends Expression implements Spec { const Reference(this.symbol, [this.url]); @override - R accept( - SpecVisitor visitor, [ - R? context, - ]) => + R accept(SpecVisitor visitor, [R? context]) => visitor.visitReference(this, context); @override @@ -53,13 +50,12 @@ class Reference extends Expression implements Spec { Iterable positionalArguments, [ Map namedArguments = const {}, List typeArguments = const [], - ]) => - InvokeExpression.newOf( - this, - positionalArguments.toList(), - namedArguments, - typeArguments, - ); + ]) => InvokeExpression.newOf( + this, + positionalArguments.toList(), + namedArguments, + typeArguments, + ); /// Returns a new instance of this expression with a named constructor. Expression newInstanceNamed( @@ -67,27 +63,25 @@ class Reference extends Expression implements Spec { Iterable positionalArguments, [ Map namedArguments = const {}, List typeArguments = const [], - ]) => - InvokeExpression.newOf( - this, - positionalArguments.toList(), - namedArguments, - typeArguments, - name, - ); + ]) => InvokeExpression.newOf( + this, + positionalArguments.toList(), + namedArguments, + typeArguments, + name, + ); /// Returns a const instance of this expression. Expression constInstance( Iterable positionalArguments, [ Map namedArguments = const {}, List typeArguments = const [], - ]) => - InvokeExpression.constOf( - this, - positionalArguments.toList(), - namedArguments, - typeArguments, - ); + ]) => InvokeExpression.constOf( + this, + positionalArguments.toList(), + namedArguments, + typeArguments, + ); /// Returns a const instance of this expression with a named constructor. Expression constInstanceNamed( @@ -95,26 +89,29 @@ class Reference extends Expression implements Spec { Iterable positionalArguments, [ Map namedArguments = const {}, List typeArguments = const [], - ]) => - InvokeExpression.constOf( - this, - positionalArguments.toList(), - namedArguments, - typeArguments, - name, - ); + ]) => InvokeExpression.constOf( + this, + positionalArguments.toList(), + namedArguments, + typeArguments, + name, + ); @override Expression get expression => CodeExpression(Code.scope((a) => a(this))); @override - String toString() => (newBuiltValueToStringHelper('Reference') - ..add('url', url) - ..add('symbol', symbol)) - .toString(); + String toString() => + (newBuiltValueToStringHelper('Reference') + ..add('url', url) + ..add('symbol', symbol)) + .toString(); /// Returns as a [TypeReference], which allows adding generic type parameters. - Reference get type => TypeReference((b) => b - ..url = url - ..symbol = symbol); + Reference get type => TypeReference( + (b) => + b + ..url = url + ..symbol = symbol, + ); } diff --git a/pkgs/code_builder/lib/src/specs/type_function.dart b/pkgs/code_builder/lib/src/specs/type_function.dart index be7c3eacc..57287f4a1 100644 --- a/pkgs/code_builder/lib/src/specs/type_function.dart +++ b/pkgs/code_builder/lib/src/specs/type_function.dart @@ -19,17 +19,13 @@ part 'type_function.g.dart'; abstract class FunctionType extends Expression with HasGenerics implements Built, Reference, Spec { - factory FunctionType([ - void Function(FunctionTypeBuilder) updates, - ]) = _$FunctionType; + factory FunctionType([void Function(FunctionTypeBuilder) updates]) = + _$FunctionType; FunctionType._(); @override - R accept( - SpecVisitor visitor, [ - R? context, - ]) => + R accept(SpecVisitor visitor, [R? context]) => visitor.visitFunctionType(this, context); /// Return type. @@ -70,8 +66,7 @@ abstract class FunctionType extends Expression Iterable positionalArguments, [ Map namedArguments = const {}, List typeArguments = const [], - ]) => - throw UnsupportedError('Cannot instantiate a function type.'); + ]) => throw UnsupportedError('Cannot instantiate a function type.'); @override Expression newInstanceNamed( @@ -79,16 +74,14 @@ abstract class FunctionType extends Expression Iterable positionalArguments, [ Map namedArguments = const {}, List typeArguments = const [], - ]) => - throw UnsupportedError('Cannot instantiate a function type.'); + ]) => throw UnsupportedError('Cannot instantiate a function type.'); @override Expression constInstance( Iterable positionalArguments, [ Map namedArguments = const {}, List typeArguments = const [], - ]) => - throw UnsupportedError('Cannot "const" a function type.'); + ]) => throw UnsupportedError('Cannot "const" a function type.'); @override Expression constInstanceNamed( @@ -96,8 +89,7 @@ abstract class FunctionType extends Expression Iterable positionalArguments, [ Map namedArguments = const {}, List typeArguments = const [], - ]) => - throw UnsupportedError('Cannot "const" a function type.'); + ]) => throw UnsupportedError('Cannot "const" a function type.'); /// A typedef assignment to this type. Code toTypeDef(String name) => createTypeDef(name, this); diff --git a/pkgs/code_builder/lib/src/specs/type_function.g.dart b/pkgs/code_builder/lib/src/specs/type_function.g.dart index d09f59b03..d817c407f 100644 --- a/pkgs/code_builder/lib/src/specs/type_function.g.dart +++ b/pkgs/code_builder/lib/src/specs/type_function.g.dart @@ -25,24 +25,36 @@ class _$FunctionType extends FunctionType { factory _$FunctionType([void Function(FunctionTypeBuilder)? updates]) => (new FunctionTypeBuilder()..update(updates)).build() as _$FunctionType; - _$FunctionType._( - {this.returnType, - required this.types, - required this.requiredParameters, - required this.optionalParameters, - required this.namedParameters, - required this.namedRequiredParameters, - this.isNullable}) - : super._() { + _$FunctionType._({ + this.returnType, + required this.types, + required this.requiredParameters, + required this.optionalParameters, + required this.namedParameters, + required this.namedRequiredParameters, + this.isNullable, + }) : super._() { BuiltValueNullFieldError.checkNotNull(types, r'FunctionType', 'types'); BuiltValueNullFieldError.checkNotNull( - requiredParameters, r'FunctionType', 'requiredParameters'); + requiredParameters, + r'FunctionType', + 'requiredParameters', + ); BuiltValueNullFieldError.checkNotNull( - optionalParameters, r'FunctionType', 'optionalParameters'); + optionalParameters, + r'FunctionType', + 'optionalParameters', + ); BuiltValueNullFieldError.checkNotNull( - namedParameters, r'FunctionType', 'namedParameters'); + namedParameters, + r'FunctionType', + 'namedParameters', + ); BuiltValueNullFieldError.checkNotNull( - namedRequiredParameters, r'FunctionType', 'namedRequiredParameters'); + namedRequiredParameters, + r'FunctionType', + 'namedRequiredParameters', + ); } @override @@ -165,7 +177,8 @@ class _$FunctionTypeBuilder extends FunctionTypeBuilder { @override set namedRequiredParameters( - MapBuilder namedRequiredParameters) { + MapBuilder namedRequiredParameters, + ) { _$this; super.namedRequiredParameters = namedRequiredParameters; } @@ -216,15 +229,17 @@ class _$FunctionTypeBuilder extends FunctionTypeBuilder { _$FunctionType _build() { _$FunctionType _$result; try { - _$result = _$v ?? + _$result = + _$v ?? new _$FunctionType._( - returnType: returnType, - types: types.build(), - requiredParameters: requiredParameters.build(), - optionalParameters: optionalParameters.build(), - namedParameters: namedParameters.build(), - namedRequiredParameters: namedRequiredParameters.build(), - isNullable: isNullable); + returnType: returnType, + types: types.build(), + requiredParameters: requiredParameters.build(), + optionalParameters: optionalParameters.build(), + namedParameters: namedParameters.build(), + namedRequiredParameters: namedRequiredParameters.build(), + isNullable: isNullable, + ); } catch (_) { late String _$failedField; try { @@ -240,7 +255,10 @@ class _$FunctionTypeBuilder extends FunctionTypeBuilder { namedRequiredParameters.build(); } catch (e) { throw new BuiltValueNestedFieldError( - r'FunctionType', _$failedField, e.toString()); + r'FunctionType', + _$failedField, + e.toString(), + ); } rethrow; } diff --git a/pkgs/code_builder/lib/src/specs/type_record.dart b/pkgs/code_builder/lib/src/specs/type_record.dart index 2f0594c77..939f30e17 100644 --- a/pkgs/code_builder/lib/src/specs/type_record.dart +++ b/pkgs/code_builder/lib/src/specs/type_record.dart @@ -16,17 +16,12 @@ part 'type_record.g.dart'; @immutable abstract class RecordType extends Expression implements Built, Reference, Spec { - factory RecordType([ - void Function(RecordTypeBuilder) updates, - ]) = _$RecordType; + factory RecordType([void Function(RecordTypeBuilder) updates]) = _$RecordType; RecordType._(); @override - R accept( - SpecVisitor visitor, [ - R? context, - ]) => + R accept(SpecVisitor visitor, [R? context]) => visitor.visitRecordType(this, context); BuiltList get positionalFieldTypes; @@ -50,8 +45,7 @@ abstract class RecordType extends Expression Iterable positionalArguments, [ Map namedArguments = const {}, List typeArguments = const [], - ]) => - throw UnsupportedError('Cannot instantiate a record type.'); + ]) => throw UnsupportedError('Cannot instantiate a record type.'); @override Expression newInstanceNamed( @@ -59,16 +53,14 @@ abstract class RecordType extends Expression Iterable positionalArguments, [ Map namedArguments = const {}, List typeArguments = const [], - ]) => - throw UnsupportedError('Cannot instantiate a record type.'); + ]) => throw UnsupportedError('Cannot instantiate a record type.'); @override Expression constInstance( Iterable positionalArguments, [ Map namedArguments = const {}, List typeArguments = const [], - ]) => - throw UnsupportedError('Cannot "const" a record type.'); + ]) => throw UnsupportedError('Cannot "const" a record type.'); @override Expression constInstanceNamed( @@ -76,8 +68,7 @@ abstract class RecordType extends Expression Iterable positionalArguments, [ Map namedArguments = const {}, List typeArguments = const [], - ]) => - throw UnsupportedError('Cannot "const" a record type.'); + ]) => throw UnsupportedError('Cannot "const" a record type.'); } abstract class RecordTypeBuilder extends Object diff --git a/pkgs/code_builder/lib/src/specs/type_record.g.dart b/pkgs/code_builder/lib/src/specs/type_record.g.dart index b1d47dfbd..b36108691 100644 --- a/pkgs/code_builder/lib/src/specs/type_record.g.dart +++ b/pkgs/code_builder/lib/src/specs/type_record.g.dart @@ -17,15 +17,21 @@ class _$RecordType extends RecordType { factory _$RecordType([void Function(RecordTypeBuilder)? updates]) => (new RecordTypeBuilder()..update(updates)).build() as _$RecordType; - _$RecordType._( - {required this.positionalFieldTypes, - required this.namedFieldTypes, - this.isNullable}) - : super._() { + _$RecordType._({ + required this.positionalFieldTypes, + required this.namedFieldTypes, + this.isNullable, + }) : super._() { BuiltValueNullFieldError.checkNotNull( - positionalFieldTypes, r'RecordType', 'positionalFieldTypes'); + positionalFieldTypes, + r'RecordType', + 'positionalFieldTypes', + ); BuiltValueNullFieldError.checkNotNull( - namedFieldTypes, r'RecordType', 'namedFieldTypes'); + namedFieldTypes, + r'RecordType', + 'namedFieldTypes', + ); } @override @@ -133,11 +139,13 @@ class _$RecordTypeBuilder extends RecordTypeBuilder { _$RecordType _build() { _$RecordType _$result; try { - _$result = _$v ?? + _$result = + _$v ?? new _$RecordType._( - positionalFieldTypes: positionalFieldTypes.build(), - namedFieldTypes: namedFieldTypes.build(), - isNullable: isNullable); + positionalFieldTypes: positionalFieldTypes.build(), + namedFieldTypes: namedFieldTypes.build(), + isNullable: isNullable, + ); } catch (_) { late String _$failedField; try { @@ -147,7 +155,10 @@ class _$RecordTypeBuilder extends RecordTypeBuilder { namedFieldTypes.build(); } catch (e) { throw new BuiltValueNestedFieldError( - r'RecordType', _$failedField, e.toString()); + r'RecordType', + _$failedField, + e.toString(), + ); } rethrow; } diff --git a/pkgs/code_builder/lib/src/specs/type_reference.dart b/pkgs/code_builder/lib/src/specs/type_reference.dart index 74c7840a3..d192de588 100644 --- a/pkgs/code_builder/lib/src/specs/type_reference.dart +++ b/pkgs/code_builder/lib/src/specs/type_reference.dart @@ -19,9 +19,8 @@ part 'type_reference.g.dart'; abstract class TypeReference extends Expression with HasGenerics implements Built, Reference, Spec { - factory TypeReference([ - void Function(TypeReferenceBuilder) updates, - ]) = _$TypeReference; + factory TypeReference([void Function(TypeReferenceBuilder) updates]) = + _$TypeReference; TypeReference._(); @@ -44,10 +43,7 @@ abstract class TypeReference extends Expression bool? get isNullable; @override - R accept( - SpecVisitor visitor, [ - R? context, - ]) => + R accept(SpecVisitor visitor, [R? context]) => visitor.visitType(this, context); @override @@ -61,13 +57,12 @@ abstract class TypeReference extends Expression Iterable positionalArguments, [ Map namedArguments = const {}, List typeArguments = const [], - ]) => - InvokeExpression.newOf( - this, - positionalArguments.toList(), - namedArguments, - typeArguments, - ); + ]) => InvokeExpression.newOf( + this, + positionalArguments.toList(), + namedArguments, + typeArguments, + ); @override Expression newInstanceNamed( @@ -75,27 +70,25 @@ abstract class TypeReference extends Expression Iterable positionalArguments, [ Map namedArguments = const {}, List typeArguments = const [], - ]) => - InvokeExpression.newOf( - this, - positionalArguments.toList(), - namedArguments, - typeArguments, - name, - ); + ]) => InvokeExpression.newOf( + this, + positionalArguments.toList(), + namedArguments, + typeArguments, + name, + ); @override Expression constInstance( Iterable positionalArguments, [ Map namedArguments = const {}, List typeArguments = const [], - ]) => - InvokeExpression.constOf( - this, - positionalArguments.toList(), - namedArguments, - typeArguments, - ); + ]) => InvokeExpression.constOf( + this, + positionalArguments.toList(), + namedArguments, + typeArguments, + ); @override Expression constInstanceNamed( @@ -103,14 +96,13 @@ abstract class TypeReference extends Expression Iterable positionalArguments, [ Map namedArguments = const {}, List typeArguments = const [], - ]) => - InvokeExpression.constOf( - this, - positionalArguments.toList(), - namedArguments, - typeArguments, - name, - ); + ]) => InvokeExpression.constOf( + this, + positionalArguments.toList(), + namedArguments, + typeArguments, + name, + ); } abstract class TypeReferenceBuilder extends Object diff --git a/pkgs/code_builder/lib/src/specs/type_reference.g.dart b/pkgs/code_builder/lib/src/specs/type_reference.g.dart index 124e8b4f0..d6b1677c0 100644 --- a/pkgs/code_builder/lib/src/specs/type_reference.g.dart +++ b/pkgs/code_builder/lib/src/specs/type_reference.g.dart @@ -21,13 +21,13 @@ class _$TypeReference extends TypeReference { factory _$TypeReference([void Function(TypeReferenceBuilder)? updates]) => (new TypeReferenceBuilder()..update(updates)).build() as _$TypeReference; - _$TypeReference._( - {required this.symbol, - this.url, - this.bound, - required this.types, - this.isNullable}) - : super._() { + _$TypeReference._({ + required this.symbol, + this.url, + this.bound, + required this.types, + this.isNullable, + }) : super._() { BuiltValueNullFieldError.checkNotNull(symbol, r'TypeReference', 'symbol'); BuiltValueNullFieldError.checkNotNull(types, r'TypeReference', 'types'); } @@ -170,14 +170,19 @@ class _$TypeReferenceBuilder extends TypeReferenceBuilder { _$TypeReference _build() { _$TypeReference _$result; try { - _$result = _$v ?? + _$result = + _$v ?? new _$TypeReference._( - symbol: BuiltValueNullFieldError.checkNotNull( - symbol, r'TypeReference', 'symbol'), - url: url, - bound: bound, - types: types.build(), - isNullable: isNullable); + symbol: BuiltValueNullFieldError.checkNotNull( + symbol, + r'TypeReference', + 'symbol', + ), + url: url, + bound: bound, + types: types.build(), + isNullable: isNullable, + ); } catch (_) { late String _$failedField; try { @@ -185,7 +190,10 @@ class _$TypeReferenceBuilder extends TypeReferenceBuilder { types.build(); } catch (e) { throw new BuiltValueNestedFieldError( - r'TypeReference', _$failedField, e.toString()); + r'TypeReference', + _$failedField, + e.toString(), + ); } rethrow; } diff --git a/pkgs/code_builder/lib/src/specs/typedef.dart b/pkgs/code_builder/lib/src/specs/typedef.dart index fe5d8f12c..c31afa56c 100644 --- a/pkgs/code_builder/lib/src/specs/typedef.dart +++ b/pkgs/code_builder/lib/src/specs/typedef.dart @@ -33,10 +33,7 @@ abstract class TypeDef extends Object Expression get definition; @override - R accept( - SpecVisitor visitor, [ - R? context, - ]) => + R accept(SpecVisitor visitor, [R? context]) => visitor.visitTypeDef(this, context); } diff --git a/pkgs/code_builder/lib/src/specs/typedef.g.dart b/pkgs/code_builder/lib/src/specs/typedef.g.dart index 8c2a16c2d..e1d1f556e 100644 --- a/pkgs/code_builder/lib/src/specs/typedef.g.dart +++ b/pkgs/code_builder/lib/src/specs/typedef.g.dart @@ -21,17 +21,20 @@ class _$TypeDef extends TypeDef { factory _$TypeDef([void Function(TypeDefBuilder)? updates]) => (new TypeDefBuilder()..update(updates)).build() as _$TypeDef; - _$TypeDef._( - {required this.name, - required this.definition, - required this.annotations, - required this.docs, - required this.types}) - : super._() { + _$TypeDef._({ + required this.name, + required this.definition, + required this.annotations, + required this.docs, + required this.types, + }) : super._() { BuiltValueNullFieldError.checkNotNull(name, r'TypeDef', 'name'); BuiltValueNullFieldError.checkNotNull(definition, r'TypeDef', 'definition'); BuiltValueNullFieldError.checkNotNull( - annotations, r'TypeDef', 'annotations'); + annotations, + r'TypeDef', + 'annotations', + ); BuiltValueNullFieldError.checkNotNull(docs, r'TypeDef', 'docs'); BuiltValueNullFieldError.checkNotNull(types, r'TypeDef', 'types'); } @@ -173,15 +176,23 @@ class _$TypeDefBuilder extends TypeDefBuilder { _$TypeDef _build() { _$TypeDef _$result; try { - _$result = _$v ?? + _$result = + _$v ?? new _$TypeDef._( - name: BuiltValueNullFieldError.checkNotNull( - name, r'TypeDef', 'name'), - definition: BuiltValueNullFieldError.checkNotNull( - definition, r'TypeDef', 'definition'), - annotations: annotations.build(), - docs: docs.build(), - types: types.build()); + name: BuiltValueNullFieldError.checkNotNull( + name, + r'TypeDef', + 'name', + ), + definition: BuiltValueNullFieldError.checkNotNull( + definition, + r'TypeDef', + 'definition', + ), + annotations: annotations.build(), + docs: docs.build(), + types: types.build(), + ); } catch (_) { late String _$failedField; try { @@ -193,7 +204,10 @@ class _$TypeDefBuilder extends TypeDefBuilder { types.build(); } catch (e) { throw new BuiltValueNestedFieldError( - r'TypeDef', _$failedField, e.toString()); + r'TypeDef', + _$failedField, + e.toString(), + ); } rethrow; } diff --git a/pkgs/code_builder/pubspec.yaml b/pkgs/code_builder/pubspec.yaml index 6bf096579..ebf286e98 100644 --- a/pkgs/code_builder/pubspec.yaml +++ b/pkgs/code_builder/pubspec.yaml @@ -1,24 +1,24 @@ name: code_builder -version: 4.10.2-wip +version: 4.11.0 description: A fluent, builder-based library for generating valid Dart code. repository: https://github.com/dart-lang/tools/tree/main/pkgs/code_builder issue_tracker: https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Acode_builder environment: - sdk: ^3.6.0 + sdk: ^3.7.0 dependencies: - built_collection: ^5.0.0 - built_value: ^8.0.0 - collection: ^1.15.0 - matcher: ^0.12.10 - meta: ^1.3.0 + built_collection: ^5.1.1 + built_value: ^8.10.1 + collection: ^1.19.0 + matcher: ^0.12.16+1 + meta: ^1.16.0 dev_dependencies: - build: ^2.0.0 - build_runner: ^2.0.3 - built_value_generator: ^8.0.0 + build: ^4.0.0 + build_runner: ^2.7.2 + built_value_generator: ^8.11.2 dart_flutter_team_lints: ^3.0.0 - dart_style: ^3.0.1 - source_gen: ^2.0.0 - test: ^1.16.0 + dart_style: ^3.1.2 + source_gen: ^4.0.1 + test: ^1.26.3 diff --git a/pkgs/code_builder/test/allocator_test.dart b/pkgs/code_builder/test/allocator_test.dart index 09f135c56..71c93cbf2 100644 --- a/pkgs/code_builder/test/allocator_test.dart +++ b/pkgs/code_builder/test/allocator_test.dart @@ -19,10 +19,11 @@ void main() { }); test('should collect import URLs', () { - allocator = Allocator() - ..allocate(refer('List', 'dart:core')) - ..allocate(refer('LinkedHashMap', 'dart:collection')) - ..allocate(refer('someSymbol')); + allocator = + Allocator() + ..allocate(refer('List', 'dart:core')) + ..allocate(refer('LinkedHashMap', 'dart:collection')) + ..allocate(refer('someSymbol')); expect(allocator.imports.map((d) => d.url), [ 'dart:core', 'dart:collection', @@ -37,10 +38,7 @@ void main() { test('.simplePrefixing should add import prefixes', () { allocator = Allocator.simplePrefixing(); - expect( - allocator.allocate(refer('List', 'dart:core')), - 'List', - ); + expect(allocator.allocate(refer('List', 'dart:core')), 'List'); expect( allocator.allocate(refer('LinkedHashMap', 'dart:collection')), '_i1.LinkedHashMap', diff --git a/pkgs/code_builder/test/const_test.dart b/pkgs/code_builder/test/const_test.dart index c4d69c61b..e8d1bc3ac 100644 --- a/pkgs/code_builder/test/const_test.dart +++ b/pkgs/code_builder/test/const_test.dart @@ -16,47 +16,72 @@ void main() { }); test('expression', () { - expect(constMap, equalsDart(r''' - const {'list': [], 'duration': Duration(), }''')); + expect( + constMap, + equalsDart(r''' + const {'list': [], 'duration': Duration(), }'''), + ); }); test('assignConst', () { expect( // ignore: deprecated_member_use_from_same_package constMap.assignConst('constField'), - equalsDart(r''' + equalsDart( + r''' const constField = {'list': [], 'duration': Duration(), }''', - DartEmitter.scoped()), + DartEmitter.scoped(), + ), ); }); test('assign to declared constant', () { expect( declareConst('constField').assign(constMap), - equalsDart(r''' + equalsDart( + r''' const constField = {'list': [], 'duration': Duration(), }''', - DartEmitter.scoped()), + DartEmitter.scoped(), + ), ); }); test('assign to declared non-constant', () { expect( - declareVar('varField').assign(constMap), - equalsDart(r''' + declareVar('varField').assign(constMap), + equalsDart( + r''' var varField = const {'list': [], 'duration': Duration(), }''', - DartEmitter.scoped())); + DartEmitter.scoped(), + ), + ); }); - final library = Library((b) => b - ..body.add(Field((b) => b - ..name = 'val1' - ..modifier = FieldModifier.constant - ..assignment = refer('ConstClass').constInstance([]).code)) - ..body.add(Field((b) => b - ..name = 'val2' - ..modifier = FieldModifier.constant - ..assignment = - refer('ConstClass').constInstanceNamed('other', []).code))); + final library = Library( + (b) => + b + ..body.add( + Field( + (b) => + b + ..name = 'val1' + ..modifier = FieldModifier.constant + ..assignment = refer('ConstClass').constInstance([]).code, + ), + ) + ..body.add( + Field( + (b) => + b + ..name = 'val2' + ..modifier = FieldModifier.constant + ..assignment = + refer( + 'ConstClass', + ).constInstanceNamed('other', []).code, + ), + ), + ); test('should emit a source file with imports in defined order', () { expect( diff --git a/pkgs/code_builder/test/directive_test.dart b/pkgs/code_builder/test/directive_test.dart index 0aee6ae57..31bd2a494 100644 --- a/pkgs/code_builder/test/directive_test.dart +++ b/pkgs/code_builder/test/directive_test.dart @@ -12,27 +12,61 @@ void main() { final $LinkedHashMap = refer('LinkedHashMap', 'dart:collection'); - final library = Library((b) => b - ..directives.add(Directive.export('../relative.dart')) - ..directives.add(Directive.export('package:foo/foo.dart')) - ..directives.add(Directive.part('lib.g.dart')) - ..body.add(Field((b) => b - ..name = 'relativeRef' - ..modifier = FieldModifier.final$ - ..assignment = - refer('Relative', '../relative.dart').newInstance([]).code)) - ..body.add(Field((b) => b - ..name = 'pkgRefFoo' - ..modifier = FieldModifier.final$ - ..assignment = refer('Foo', 'package:foo/foo.dart').newInstance([]).code)) - ..body.add(Field((b) => b - ..name = 'pkgRefBar' - ..modifier = FieldModifier.final$ - ..assignment = refer('Bar', 'package:foo/bar.dart').newInstance([]).code)) - ..body.add(Field((b) => b - ..name = 'collectionRef' - ..modifier = FieldModifier.final$ - ..assignment = $LinkedHashMap.newInstance([]).code))); + final library = Library( + (b) => + b + ..directives.add(Directive.export('../relative.dart')) + ..directives.add(Directive.export('package:foo/foo.dart')) + ..directives.add(Directive.part('lib.g.dart')) + ..body.add( + Field( + (b) => + b + ..name = 'relativeRef' + ..modifier = FieldModifier.final$ + ..assignment = + refer( + 'Relative', + '../relative.dart', + ).newInstance([]).code, + ), + ) + ..body.add( + Field( + (b) => + b + ..name = 'pkgRefFoo' + ..modifier = FieldModifier.final$ + ..assignment = + refer( + 'Foo', + 'package:foo/foo.dart', + ).newInstance([]).code, + ), + ) + ..body.add( + Field( + (b) => + b + ..name = 'pkgRefBar' + ..modifier = FieldModifier.final$ + ..assignment = + refer( + 'Bar', + 'package:foo/bar.dart', + ).newInstance([]).code, + ), + ) + ..body.add( + Field( + (b) => + b + ..name = 'collectionRef' + ..modifier = FieldModifier.final$ + ..assignment = $LinkedHashMap.newInstance([]).code, + ), + ), + ); test('should emit a source file with imports in defined order', () { expect( @@ -57,7 +91,8 @@ void main() { test('should emit a source file with ordered', () { expect( library, - equalsDart(r''' + equalsDart( + r''' // ignore_for_file: no_leading_underscores_for_library_prefixes import 'dart:collection' as _i4; @@ -75,7 +110,8 @@ void main() { final pkgRefFoo = _i2.Foo(); final pkgRefBar = _i3.Bar(); final collectionRef = _i4.LinkedHashMap();''', - DartEmitter.scoped(orderDirectives: true)), + DartEmitter.scoped(orderDirectives: true), + ), ); }); } diff --git a/pkgs/code_builder/test/e2e/injection_test.dart b/pkgs/code_builder/test/e2e/injection_test.dart index 129f02cd1..fac43da72 100644 --- a/pkgs/code_builder/test/e2e/injection_test.dart +++ b/pkgs/code_builder/test/e2e/injection_test.dart @@ -16,25 +16,47 @@ void main() { final $Module = refer('Module', 'package:app/module.dart'); final $Thing = refer('Thing', 'package:app/thing.dart'); - final clazz = ClassBuilder() - ..name = 'Injector' - ..implements.add($App) - ..fields.add(Field((b) => b - ..modifier = FieldModifier.final$ - ..name = '_module' - ..type = $Module.type)) - ..constructors.add(Constructor((b) => b - ..requiredParameters.add(Parameter((b) => b - ..name = '_module' - ..toThis = true)))) - ..methods.add(Method((b) => b - ..name = 'getThing' - ..body = $Thing.newInstance([ - refer('_module').property('get1').call([]), - refer('_module').property('get2').call([]), - ]).code - ..returns = $Thing - ..annotations.add(refer('override')))); + final clazz = + ClassBuilder() + ..name = 'Injector' + ..implements.add($App) + ..fields.add( + Field( + (b) => + b + ..modifier = FieldModifier.final$ + ..name = '_module' + ..type = $Module.type, + ), + ) + ..constructors.add( + Constructor( + (b) => + b + ..requiredParameters.add( + Parameter( + (b) => + b + ..name = '_module' + ..toThis = true, + ), + ), + ), + ) + ..methods.add( + Method( + (b) => + b + ..name = 'getThing' + ..body = + $Thing.newInstance([ + refer('_module').property('get1').call([]), + refer('_module').property('get2').call([]), + ]).code + ..returns = $Thing + ..annotations.add(refer('override')), + ), + ); expect( clazz.build(), diff --git a/pkgs/code_builder/test/matcher_test.dart b/pkgs/code_builder/test/matcher_test.dart index c9475a847..bb4c9cf16 100644 --- a/pkgs/code_builder/test/matcher_test.dart +++ b/pkgs/code_builder/test/matcher_test.dart @@ -23,8 +23,14 @@ void main() { extension on Matcher { void expectMismatch(dynamic actual, String mismatch) { expect( - () => expect(actual, this), - throwsA(isA().having( - (e) => e.message, 'message', equalsIgnoringWhitespace(mismatch)))); + () => expect(actual, this), + throwsA( + isA().having( + (e) => e.message, + 'message', + equalsIgnoringWhitespace(mismatch), + ), + ), + ); } } diff --git a/pkgs/code_builder/test/specs/class_test.dart b/pkgs/code_builder/test/specs/class_test.dart index 562bca4c6..3bd990233 100644 --- a/pkgs/code_builder/test/specs/class_test.dart +++ b/pkgs/code_builder/test/specs/class_test.dart @@ -21,9 +21,12 @@ void main() { test('should create an abstract class', () { expect( - Class((b) => b - ..name = 'Foo' - ..abstract = true), + Class( + (b) => + b + ..name = 'Foo' + ..abstract = true, + ), equalsDart(r''' abstract class Foo {} '''), @@ -32,10 +35,13 @@ void main() { test('should create an abstract base class', () { expect( - Class((b) => b - ..name = 'Foo' - ..abstract = true - ..modifier = ClassModifier.base), + Class( + (b) => + b + ..name = 'Foo' + ..abstract = true + ..modifier = ClassModifier.base, + ), equalsDart(r''' abstract base class Foo {} '''), @@ -44,9 +50,12 @@ void main() { test('should create a final class', () { expect( - Class((b) => b - ..name = 'Foo' - ..modifier = ClassModifier.final$), + Class( + (b) => + b + ..name = 'Foo' + ..modifier = ClassModifier.final$, + ), equalsDart(r''' final class Foo {} '''), @@ -55,9 +64,12 @@ void main() { test('should create a sealed class', () { expect( - Class((b) => b - ..name = 'Foo' - ..sealed = true), + Class( + (b) => + b + ..name = 'Foo' + ..sealed = true, + ), equalsDart(r''' sealed class Foo {} '''), @@ -66,10 +78,13 @@ void main() { test('should create an abstract interface class', () { expect( - Class((b) => b - ..name = 'Foo' - ..abstract = true - ..modifier = ClassModifier.interface), + Class( + (b) => + b + ..name = 'Foo' + ..abstract = true + ..modifier = ClassModifier.interface, + ), equalsDart(r''' abstract interface class Foo {} '''), @@ -78,9 +93,12 @@ void main() { test('should create a mixin class', () { expect( - Class((b) => b - ..name = 'Foo' - ..mixin = true), + Class( + (b) => + b + ..name = 'Foo' + ..mixin = true, + ), equalsDart(r''' mixin class Foo {} '''), @@ -89,10 +107,13 @@ void main() { test('should create an abstract mixin class', () { expect( - Class((b) => b - ..name = 'Foo' - ..abstract = true - ..mixin = true), + Class( + (b) => + b + ..name = 'Foo' + ..abstract = true + ..mixin = true, + ), equalsDart(r''' abstract mixin class Foo {} '''), @@ -101,10 +122,13 @@ void main() { test('should create a base mixin class', () { expect( - Class((b) => b - ..name = 'Foo' - ..mixin = true - ..modifier = ClassModifier.base), + Class( + (b) => + b + ..name = 'Foo' + ..mixin = true + ..modifier = ClassModifier.base, + ), equalsDart(r''' base mixin class Foo {} '''), @@ -113,11 +137,14 @@ void main() { test('should create an abstract base mixin class', () { expect( - Class((b) => b - ..name = 'Foo' - ..abstract = true - ..mixin = true - ..modifier = ClassModifier.base), + Class( + (b) => + b + ..name = 'Foo' + ..abstract = true + ..mixin = true + ..modifier = ClassModifier.base, + ), equalsDart(r''' abstract base mixin class Foo {} '''), @@ -127,13 +154,10 @@ void main() { test('should create a class with documentations', () { expect( Class( - (b) => b - ..name = 'Foo' - ..docs.addAll( - const [ - '/// My favorite class.', - ], - ), + (b) => + b + ..name = 'Foo' + ..docs.addAll(const ['/// My favorite class.']), ), equalsDart(r''' /// My favorite class. @@ -145,12 +169,15 @@ void main() { test('should create a class with annotations', () { expect( Class( - (b) => b - ..name = 'Foo' - ..annotations.addAll([ - refer('deprecated'), - refer('Deprecated').call([literalString('This is an old class')]) - ]), + (b) => + b + ..name = 'Foo' + ..annotations.addAll([ + refer('deprecated'), + refer( + 'Deprecated', + ).call([literalString('This is an old class')]), + ]), ), equalsDart(r''' @deprecated @@ -162,9 +189,12 @@ void main() { test('should create a class with a generic type', () { expect( - Class((b) => b - ..name = 'List' - ..types.add(refer('T'))), + Class( + (b) => + b + ..name = 'List' + ..types.add(refer('T')), + ), equalsDart(r''' class List {} '''), @@ -174,12 +204,10 @@ void main() { test('should create a class with multiple generic types', () { expect( Class( - (b) => b - ..name = 'Map' - ..types.addAll([ - refer('K'), - refer('V'), - ]), + (b) => + b + ..name = 'Map' + ..types.addAll([refer('K'), refer('V')]), ), equalsDart(r''' class Map {} @@ -189,13 +217,24 @@ void main() { test('should create a class with a bound generic type', () { expect( - Class((b) => b - ..name = 'Comparable' - ..types.add(TypeReference((b) => b - ..symbol = 'T' - ..bound = TypeReference((b) => b - ..symbol = 'Comparable' - ..types.add(refer('T').type))))), + Class( + (b) => + b + ..name = 'Comparable' + ..types.add( + TypeReference( + (b) => + b + ..symbol = 'T' + ..bound = TypeReference( + (b) => + b + ..symbol = 'Comparable' + ..types.add(refer('T').type), + ), + ), + ), + ), equalsDart(r''' class Comparable> {} '''), @@ -204,9 +243,12 @@ void main() { test('should create a class extending another class', () { expect( - Class((b) => b - ..name = 'Foo' - ..extend = TypeReference((b) => b.symbol = 'Bar')), + Class( + (b) => + b + ..name = 'Foo' + ..extend = TypeReference((b) => b.symbol = 'Bar'), + ), equalsDart(r''' class Foo extends Bar {} '''), @@ -215,10 +257,13 @@ void main() { test('should create a class mixing in another class', () { expect( - Class((b) => b - ..name = 'Foo' - ..extend = TypeReference((b) => b.symbol = 'Bar') - ..mixins.add(TypeReference((b) => b.symbol = 'Foo'))), + Class( + (b) => + b + ..name = 'Foo' + ..extend = TypeReference((b) => b.symbol = 'Bar') + ..mixins.add(TypeReference((b) => b.symbol = 'Foo')), + ), equalsDart(r''' class Foo extends Bar with Foo {} '''), @@ -227,10 +272,13 @@ void main() { test('should create a class implementing another class', () { expect( - Class((b) => b - ..name = 'Foo' - ..extend = TypeReference((b) => b.symbol = 'Bar') - ..implements.add(TypeReference((b) => b.symbol = 'Foo'))), + Class( + (b) => + b + ..name = 'Foo' + ..extend = TypeReference((b) => b.symbol = 'Bar') + ..implements.add(TypeReference((b) => b.symbol = 'Foo')), + ), equalsDart(r''' class Foo extends Bar implements Foo {} '''), @@ -239,9 +287,12 @@ void main() { test('should create a class with a constructor', () { expect( - Class((b) => b - ..name = 'Foo' - ..constructors.add(Constructor())), + Class( + (b) => + b + ..name = 'Foo' + ..constructors.add(Constructor()), + ), equalsDart(r''' class Foo { Foo(); @@ -253,17 +304,19 @@ void main() { test('should create a class with a constructor with initializers', () { expect( Class( - (b) => b - ..name = 'Foo' - ..constructors.add( - Constructor( - (b) => b - ..initializers.addAll([ - const Code('a = 5'), - const Code('super()'), - ]), - ), - ), + (b) => + b + ..name = 'Foo' + ..constructors.add( + Constructor( + (b) => + b + ..initializers.addAll([ + const Code('a = 5'), + const Code('super()'), + ]), + ), + ), ), equalsDart(r''' class Foo { @@ -275,10 +328,14 @@ void main() { test('should create a class with a annotated constructor', () { expect( - Class((b) => b - ..name = 'Foo' - ..constructors - .add(Constructor((b) => b..annotations.add(refer('deprecated'))))), + Class( + (b) => + b + ..name = 'Foo' + ..constructors.add( + Constructor((b) => b..annotations.add(refer('deprecated'))), + ), + ), equalsDart(r''' class Foo { @deprecated @@ -290,9 +347,12 @@ void main() { test('should create a class with a named constructor', () { expect( - Class((b) => b - ..name = 'Foo' - ..constructors.add(Constructor((b) => b..name = 'named'))), + Class( + (b) => + b + ..name = 'Foo' + ..constructors.add(Constructor((b) => b..name = 'named')), + ), equalsDart(r''' class Foo { Foo.named(); @@ -303,9 +363,12 @@ void main() { test('should create a class with a const constructor', () { expect( - Class((b) => b - ..name = 'Foo' - ..constructors.add(Constructor((b) => b..constant = true))), + Class( + (b) => + b + ..name = 'Foo' + ..constructors.add(Constructor((b) => b..constant = true)), + ), equalsDart(r''' class Foo { const Foo(); @@ -316,9 +379,12 @@ void main() { test('should create a class with an external constructor', () { expect( - Class((b) => b - ..name = 'Foo' - ..constructors.add(Constructor((b) => b..external = true))), + Class( + (b) => + b + ..name = 'Foo' + ..constructors.add(Constructor((b) => b..external = true)), + ), equalsDart(r''' class Foo { external Foo(); @@ -329,11 +395,19 @@ void main() { test('should create a class with a factory constructor', () { expect( - Class((b) => b - ..name = 'Foo' - ..constructors.add(Constructor((b) => b - ..factory = true - ..redirect = refer('_Foo')))), + Class( + (b) => + b + ..name = 'Foo' + ..constructors.add( + Constructor( + (b) => + b + ..factory = true + ..redirect = refer('_Foo'), + ), + ), + ), equalsDart(r''' class Foo { factory Foo() = _Foo; @@ -344,12 +418,20 @@ void main() { test('should create a class with a const factory constructor', () { expect( - Class((b) => b - ..name = 'Foo' - ..constructors.add(Constructor((b) => b - ..factory = true - ..constant = true - ..redirect = refer('_Foo')))), + Class( + (b) => + b + ..name = 'Foo' + ..constructors.add( + Constructor( + (b) => + b + ..factory = true + ..constant = true + ..redirect = refer('_Foo'), + ), + ), + ), equalsDart(r''' class Foo { const factory Foo() = _Foo; @@ -360,12 +442,20 @@ void main() { test('should create a class with a factory lambda constructor', () { expect( - Class((b) => b - ..name = 'Foo' - ..constructors.add(Constructor((b) => b - ..factory = true - ..lambda = true - ..body = const Code('_Foo()')))), + Class( + (b) => + b + ..name = 'Foo' + ..constructors.add( + Constructor( + (b) => + b + ..factory = true + ..lambda = true + ..body = const Code('_Foo()'), + ), + ), + ), equalsDart(r''' class Foo { factory Foo() => _Foo(); @@ -376,11 +466,19 @@ void main() { test('should create a class with an implicit factory lambda constructor', () { expect( - Class((b) => b - ..name = 'Foo' - ..constructors.add(Constructor((b) => b - ..factory = true - ..body = refer('_Foo').newInstance([]).code))), + Class( + (b) => + b + ..name = 'Foo' + ..constructors.add( + Constructor( + (b) => + b + ..factory = true + ..body = refer('_Foo').newInstance([]).code, + ), + ), + ), equalsDart(r''' class Foo { factory Foo() => _Foo(); @@ -391,11 +489,19 @@ void main() { test('should create a class with a constructor with a body', () { expect( - Class((b) => b - ..name = 'Foo' - ..constructors.add(Constructor((b) => b - ..factory = true - ..body = const Code('return _Foo();')))), + Class( + (b) => + b + ..name = 'Foo' + ..constructors.add( + Constructor( + (b) => + b + ..factory = true + ..body = const Code('return _Foo();'), + ), + ), + ), equalsDart(r''' class Foo { factory Foo() { @@ -408,18 +514,29 @@ void main() { test('should create a class with a constructor with parameters', () { expect( - Class((b) => b - ..name = 'Foo' - ..constructors.add(Constructor((b) => b - ..requiredParameters.addAll([ - Parameter((b) => b..name = 'a'), - Parameter((b) => b..name = 'b'), - ]) - ..optionalParameters.addAll([ - Parameter((b) => b - ..name = 'c' - ..named = true), - ])))), + Class( + (b) => + b + ..name = 'Foo' + ..constructors.add( + Constructor( + (b) => + b + ..requiredParameters.addAll([ + Parameter((b) => b..name = 'a'), + Parameter((b) => b..name = 'b'), + ]) + ..optionalParameters.addAll([ + Parameter( + (b) => + b + ..name = 'c' + ..named = true, + ), + ]), + ), + ), + ), equalsDart(r''' class Foo { Foo(a, b, {c, }); @@ -430,23 +547,40 @@ void main() { test('should create a class with a constructor+field-formal parameters', () { expect( - Class((b) => b - ..name = 'Foo' - ..constructors.add(Constructor((b) => b - ..requiredParameters.addAll([ - Parameter((b) => b - ..name = 'a' - ..toThis = true), - Parameter((b) => b - ..name = 'b' - ..toThis = true), - ]) - ..optionalParameters.addAll([ - Parameter((b) => b - ..name = 'c' - ..named = true - ..toThis = true), - ])))), + Class( + (b) => + b + ..name = 'Foo' + ..constructors.add( + Constructor( + (b) => + b + ..requiredParameters.addAll([ + Parameter( + (b) => + b + ..name = 'a' + ..toThis = true, + ), + Parameter( + (b) => + b + ..name = 'b' + ..toThis = true, + ), + ]) + ..optionalParameters.addAll([ + Parameter( + (b) => + b + ..name = 'c' + ..named = true + ..toThis = true, + ), + ]), + ), + ), + ), equalsDart(r''' class Foo { Foo(this.a, this.b, {this.c, }); @@ -457,23 +591,40 @@ void main() { test('should create a class with a constructor+super-formal parameters', () { expect( - Class((b) => b - ..name = 'Foo' - ..constructors.add(Constructor((b) => b - ..requiredParameters.addAll([ - Parameter((b) => b - ..name = 'a' - ..toSuper = true), - Parameter((b) => b - ..name = 'b' - ..toSuper = true), - ]) - ..optionalParameters.addAll([ - Parameter((b) => b - ..name = 'c' - ..named = true - ..toSuper = true), - ])))), + Class( + (b) => + b + ..name = 'Foo' + ..constructors.add( + Constructor( + (b) => + b + ..requiredParameters.addAll([ + Parameter( + (b) => + b + ..name = 'a' + ..toSuper = true, + ), + Parameter( + (b) => + b + ..name = 'b' + ..toSuper = true, + ), + ]) + ..optionalParameters.addAll([ + Parameter( + (b) => + b + ..name = 'c' + ..named = true + ..toSuper = true, + ), + ]), + ), + ), + ), equalsDart(r''' class Foo { Foo(super.a, super.b, {super.c, }); diff --git a/pkgs/code_builder/test/specs/code/expression_test.dart b/pkgs/code_builder/test/specs/code/expression_test.dart index 7a424fd8e..bdf78328e 100644 --- a/pkgs/code_builder/test/specs/code/expression_test.dart +++ b/pkgs/code_builder/test/specs/code/expression_test.dart @@ -45,14 +45,19 @@ void main() { }); test('uses `onError` for unhandled types', () { expect( - literal(Uri.https('google.com'), onError: (value) { + literal( + Uri.https('google.com'), + onError: (value) { if (value is Uri) { - return refer('Uri') - .newInstanceNamed('parse', [literalString(value.toString())]); + return refer( + 'Uri', + ).newInstanceNamed('parse', [literalString(value.toString())]); } throw UnsupportedError('Not supported: $value'); - }), - equalsDart("Uri.parse('https://google.com')")); + }, + ), + equalsDart("Uri.parse('https://google.com')"), + ); }); }); @@ -162,7 +167,7 @@ void main() { Set(), true, null, - refer('Map').newInstance([]) + refer('Map').newInstance([]), ]), equalsDart('[[], {}, true, null, Map(), ]'), ); @@ -174,14 +179,13 @@ void main() { test('should emit a set of other literals and expressions', () { expect( - // ignore: prefer_collection_literals literalSet([ [], // ignore: prefer_collection_literals Set(), true, null, - refer('Map').newInstance([]) + refer('Map').newInstance([]), ]), equalsDart('{[], {}, true, null, Map(), }'), ); @@ -204,25 +208,29 @@ void main() { }); test('should emit a record with only named fields', () { - expect(literalRecord([], {'named': 1, 'other': []}), - equalsDart('(named: 1, other: [])')); + expect( + literalRecord([], {'named': 1, 'other': []}), + equalsDart('(named: 1, other: [])'), + ); }); test('should emit a record with both positional and named fields', () { - expect(literalRecord([0], {'x': true, 'y': 0}), - equalsDart('(0, x: true, y: 0)')); + expect( + literalRecord([0], {'x': true, 'y': 0}), + equalsDart('(0, x: true, y: 0)'), + ); }); test('should emit a record of other literals and expressions', () { expect( - literalRecord([ - 1, - refer('one'), - 'one' - ], { - 'named': refer('Foo').newInstance([literalNum(1)]) - }), - equalsDart("(1, one, 'one', named: Foo(1))")); + literalRecord( + [1, refer('one'), 'one'], + { + 'named': refer('Foo').newInstance([literalNum(1)]), + }, + ), + equalsDart("(1, one, 'one', named: Foo(1))"), + ); }); test('should emit a type as an expression', () { @@ -233,36 +241,26 @@ void main() { expect( refer('Foo', 'package:foo/foo.dart'), equalsDart( - '_i1.Foo', DartEmitter(allocator: Allocator.simplePrefixing())), + '_i1.Foo', + DartEmitter(allocator: Allocator.simplePrefixing()), + ), ); }); test('should emit invoking Type()', () { - expect( - refer('Map').newInstance([]), - equalsDart('Map()'), - ); + expect(refer('Map').newInstance([]), equalsDart('Map()')); }); test('should emit invoking named constructor', () { - expect( - refer('Foo').newInstanceNamed('bar', []), - equalsDart('Foo.bar()'), - ); + expect(refer('Foo').newInstanceNamed('bar', []), equalsDart('Foo.bar()')); }); test('should emit invoking unnamed constructor when name is empty', () { - expect( - refer('Foo').newInstanceNamed('', []), - equalsDart('Foo()'), - ); + expect(refer('Foo').newInstanceNamed('', []), equalsDart('Foo()')); }); test('should emit invoking const Type()', () { - expect( - refer('Object').constInstance([]), - equalsDart('const Object()'), - ); + expect(refer('Object').constInstance([]), equalsDart('const Object()')); }); test('should emit invoking a property accessor', () { @@ -278,79 +276,47 @@ void main() { }); test('should emit invoking a method with a single positional argument', () { - expect( - refer('foo').call([ - literal(1), - ]), - equalsDart('foo(1)'), - ); + expect(refer('foo').call([literal(1)]), equalsDart('foo(1)')); }); test('should emit invoking a method with positional arguments', () { expect( - refer('foo').call([ - literal(1), - literal(2), - literal(3), - ]), + refer('foo').call([literal(1), literal(2), literal(3)]), equalsDart('foo(1, 2, 3, )'), ); }); test('should emit invoking a method with a single named argument', () { expect( - refer('foo').call([], { - 'bar': literal(1), - }), + refer('foo').call([], {'bar': literal(1)}), equalsDart('foo(bar: 1)'), ); }); test('should emit invoking a method with named arguments', () { expect( - refer('foo').call([], { - 'bar': literal(1), - 'baz': literal(2), - }), + refer('foo').call([], {'bar': literal(1), 'baz': literal(2)}), equalsDart('foo(bar: 1, baz: 2, )'), ); }); test('should emit invoking a method with positional and named arguments', () { expect( - refer('foo').call([ - literal(1) - ], { - 'bar': literal(2), - 'baz': literal(3), - }), + refer('foo').call([literal(1)], {'bar': literal(2), 'baz': literal(3)}), equalsDart('foo(1, bar: 2, baz: 3, )'), ); }); test('should emit invoking a method with a single type argument', () { expect( - refer('foo').call( - [], - {}, - [ - refer('String'), - ], - ), + refer('foo').call([], {}, [refer('String')]), equalsDart('foo()'), ); }); test('should emit invoking a method with type arguments', () { expect( - refer('foo').call( - [], - {}, - [ - refer('String'), - refer('int'), - ], - ), + refer('foo').call([], {}, [refer('String'), refer('int')]), equalsDart('foo()'), ); }); @@ -371,9 +337,12 @@ void main() { test('should emit a function type with type parameters', () { expect( - FunctionType((b) => b - ..returnType = refer('T') - ..types.add(refer('T'))), + FunctionType( + (b) => + b + ..returnType = refer('T') + ..types.add(refer('T')), + ), equalsDart('T Function()'), ); }); @@ -387,46 +356,51 @@ void main() { test('should emit a function type with parameters', () { expect( - FunctionType((b) => b - ..requiredParameters.add(refer('String')) - ..optionalParameters.add(refer('int'))), + FunctionType( + (b) => + b + ..requiredParameters.add(refer('String')) + ..optionalParameters.add(refer('int')), + ), equalsDart('Function(String, [int, ])'), ); }); test('should emit a function type with named parameters', () { expect( - FunctionType((b) => b - ..namedParameters.addAll({ - 'x': refer('int'), - 'y': refer('int'), - })), + FunctionType( + (b) => + b..namedParameters.addAll({'x': refer('int'), 'y': refer('int')}), + ), equalsDart('Function({int x, int y, })'), ); }); test( - 'should emit a function type with named required and optional parameters', - () { - expect( - FunctionType((b) => b - ..namedRequiredParameters.addAll({ - 'x': refer('int'), - }) - ..namedParameters.addAll({ - 'y': refer('int'), - })), - equalsDart('Function({required int x, int y, })'), - ); - }); + 'should emit a function type with named required and optional parameters', + () { + expect( + FunctionType( + (b) => + b + ..namedRequiredParameters.addAll({'x': refer('int')}) + ..namedParameters.addAll({'y': refer('int')}), + ), + equalsDart('Function({required int x, int y, })'), + ); + }, + ); test('should emit a function type with named required parameters', () { expect( - FunctionType((b) => b - ..namedRequiredParameters.addAll({ - 'x': refer('int'), - 'y': refer('int'), - })), + FunctionType( + (b) => + b + ..namedRequiredParameters.addAll({ + 'x': refer('int'), + 'y': refer('int'), + }), + ), equalsDart('Function({required int x, required int y, })'), ); }); @@ -434,18 +408,24 @@ void main() { test('should emit a nullable function type in a Null Safety library', () { final emitter = DartEmitter.scoped(useNullSafetySyntax: true); expect( - FunctionType((b) => b - ..requiredParameters.add(refer('String')) - ..isNullable = true), + FunctionType( + (b) => + b + ..requiredParameters.add(refer('String')) + ..isNullable = true, + ), equalsDart('Function(String)?', emitter), ); }); test('should emit a nullable function type in pre-Null Safety library', () { expect( - FunctionType((b) => b - ..requiredParameters.add(refer('String')) - ..isNullable = true), + FunctionType( + (b) => + b + ..requiredParameters.add(refer('String')) + ..isNullable = true, + ), equalsDart('Function(String)'), ); }); @@ -453,22 +433,30 @@ void main() { test('should emit a non-nullable function type in a Null Safety library', () { final emitter = DartEmitter.scoped(useNullSafetySyntax: true); expect( - FunctionType((b) => b - ..requiredParameters.add(refer('String')) - ..isNullable = false), + FunctionType( + (b) => + b + ..requiredParameters.add(refer('String')) + ..isNullable = false, + ), equalsDart('Function(String)', emitter), ); }); - test('should emit a non-nullable function type in pre-Null Safety library', - () { - expect( - FunctionType((b) => b - ..requiredParameters.add(refer('String')) - ..isNullable = false), - equalsDart('Function(String)'), - ); - }); + test( + 'should emit a non-nullable function type in pre-Null Safety library', + () { + expect( + FunctionType( + (b) => + b + ..requiredParameters.add(refer('String')) + ..isNullable = false, + ), + equalsDart('Function(String)'), + ); + }, + ); test('should emit a closure', () { expect( @@ -484,26 +472,23 @@ void main() { expect( refer('map').property('putIfAbsent').call([ literalString('foo'), - Method((b) => b - ..types.add(refer('T')) - ..body = literalTrue.code).genericClosure, + Method( + (b) => + b + ..types.add(refer('T')) + ..body = literalTrue.code, + ).genericClosure, ]), equalsDart("map.putIfAbsent('foo', () => true, )"), ); }); test('should emit an assignment', () { - expect( - refer('foo').assign(literalTrue), - equalsDart('foo = true'), - ); + expect(refer('foo').assign(literalTrue), equalsDart('foo = true')); }); test('should emit an if null assignment', () { - expect( - refer('foo').ifNullThen(literalTrue), - equalsDart('foo ?? true'), - ); + expect(refer('foo').ifNullThen(literalTrue), equalsDart('foo ?? true')); }); test('should emit a null check', () { @@ -594,38 +579,23 @@ void main() { }); test('should emit await', () { - expect( - refer('future').awaited, - equalsDart('await future'), - ); + expect(refer('future').awaited, equalsDart('await future')); }); test('should emit return', () { - expect( - literalNull.returned, - equalsDart('return null'), - ); + expect(literalNull.returned, equalsDart('return null')); }); test('should emit spread', () { - expect( - refer('foo').spread, - equalsDart('...foo'), - ); + expect(refer('foo').spread, equalsDart('...foo')); }); test('should emit null safe spread', () { - expect( - refer('foo').nullSafeSpread, - equalsDart('...?foo'), - ); + expect(refer('foo').nullSafeSpread, equalsDart('...?foo')); }); test('should emit throw', () { - expect( - literalNull.thrown, - equalsDart('throw null'), - ); + expect(literalNull.thrown, equalsDart('throw null')); }); test('should emit an explicit cast', () { @@ -636,17 +606,11 @@ void main() { }); test('should emit an is check', () { - expect( - refer('foo').isA(refer('String')), - equalsDart('foo is String'), - ); + expect(refer('foo').isA(refer('String')), equalsDart('foo is String')); }); test('should emit an is! check', () { - expect( - refer('foo').isNotA(refer('String')), - equalsDart('foo is! String'), - ); + expect(refer('foo').isNotA(refer('String')), equalsDart('foo is! String')); }); test('should emit an equality check', () { @@ -703,9 +667,11 @@ void main() { }); test('should emit an operator subtract call', () { - // ignore: deprecated_member_use_from_same_package - expect(refer('foo').operatorSubstract(refer('foo2')), - equalsDart('foo - foo2')); + expect( + // ignore: deprecated_member_use_from_same_package + refer('foo').operatorSubstract(refer('foo2')), + equalsDart('foo - foo2'), + ); expect( refer('foo').operatorSubtract(refer('foo2')), @@ -715,17 +681,23 @@ void main() { test('should emit an operator divide call', () { expect( - refer('foo').operatorDivide(refer('foo2')), equalsDart('foo / foo2')); + refer('foo').operatorDivide(refer('foo2')), + equalsDart('foo / foo2'), + ); }); test('should emit an operator multiply call', () { expect( - refer('foo').operatorMultiply(refer('foo2')), equalsDart('foo * foo2')); + refer('foo').operatorMultiply(refer('foo2')), + equalsDart('foo * foo2'), + ); }); test('should emit an euclidean modulo operator call', () { - expect(refer('foo').operatorEuclideanModulo(refer('foo2')), - equalsDart('foo % foo2')); + expect( + refer('foo').operatorEuclideanModulo(refer('foo2')), + equalsDart('foo % foo2'), + ); }); test('should emit an operator int divide call', () { @@ -777,10 +749,7 @@ void main() { }); test('should emit a unary bitwise complement operator call', () { - expect( - refer('foo').operatorUnaryBitwiseComplement(), - equalsDart('~foo'), - ); + expect(refer('foo').operatorUnaryBitwiseComplement(), equalsDart('~foo')); }); test('should emit a shift left operator call', () { @@ -805,45 +774,69 @@ void main() { }); test('should emit a const variable declaration', () { - expect(declareConst('foo').assign(refer('bar')), - equalsDart('const foo = bar')); + expect( + declareConst('foo').assign(refer('bar')), + equalsDart('const foo = bar'), + ); }); test('should emit a typed const variable declaration', () { - expect(declareConst('foo', type: refer('String')).assign(refer('bar')), - equalsDart('const String foo = bar')); + expect( + declareConst('foo', type: refer('String')).assign(refer('bar')), + equalsDart('const String foo = bar'), + ); }); test('should emit a final variable declaration', () { - expect(declareFinal('foo').assign(refer('bar')), - equalsDart('final foo = bar')); + expect( + declareFinal('foo').assign(refer('bar')), + equalsDart('final foo = bar'), + ); }); test('should emit a typed final variable declaration', () { - expect(declareFinal('foo', type: refer('String')).assign(refer('bar')), - equalsDart('final String foo = bar')); + expect( + declareFinal('foo', type: refer('String')).assign(refer('bar')), + equalsDart('final String foo = bar'), + ); }); - test('should emit a nullable typed final variable declaration', () { - final emitter = DartEmitter.scoped(useNullSafetySyntax: true); - expect( - declareFinal('foo', - type: TypeReference((b) => b - ..symbol = 'String' - ..isNullable = true)).assign(refer('bar')), - equalsDart('final String? foo = bar', emitter)); - }, skip: 'https://github.com/dart-lang/code_builder/issues/315'); + test( + 'should emit a nullable typed final variable declaration', + () { + final emitter = DartEmitter.scoped(useNullSafetySyntax: true); + expect( + declareFinal( + 'foo', + type: TypeReference( + (b) => + b + ..symbol = 'String' + ..isNullable = true, + ), + ).assign(refer('bar')), + equalsDart('final String? foo = bar', emitter), + ); + }, + skip: 'https://github.com/dart-lang/code_builder/issues/315', + ); test('should emit a late final variable declaration', () { - expect(declareFinal('foo', late: true).assign(refer('bar')), - equalsDart('late final foo = bar')); + expect( + declareFinal('foo', late: true).assign(refer('bar')), + equalsDart('late final foo = bar'), + ); }); test('should emit a late typed final variable declaration', () { expect( - declareFinal('foo', type: refer('String'), late: true) - .assign(refer('bar')), - equalsDart('late final String foo = bar')); + declareFinal( + 'foo', + type: refer('String'), + late: true, + ).assign(refer('bar')), + equalsDart('late final String foo = bar'), + ); }); test('should emit a variable declaration', () { @@ -851,57 +844,51 @@ void main() { }); test('should emit a typed variable declaration', () { - expect(declareVar('foo', type: refer('String')).assign(refer('bar')), - equalsDart('String foo = bar')); + expect( + declareVar('foo', type: refer('String')).assign(refer('bar')), + equalsDart('String foo = bar'), + ); }); test('should emit a late variable declaration', () { - expect(declareVar('foo', late: true).assign(refer('bar')), - equalsDart('late var foo = bar')); + expect( + declareVar('foo', late: true).assign(refer('bar')), + equalsDart('late var foo = bar'), + ); }); test('should emit a late typed variable declaration', () { expect( - declareVar('foo', type: refer('String'), late: true) - .assign(refer('bar')), - equalsDart('late String foo = bar')); + declareVar('foo', type: refer('String'), late: true).assign(refer('bar')), + equalsDart('late String foo = bar'), + ); }); test('should emit a perenthesized epression', () { expect( - refer('foo').ifNullThen(refer('FormatException') - .newInstance([literalString('missing foo')]) - .thrown - .parenthesized), - equalsDart('foo ?? (throw FormatException(\'missing foo\'))')); + refer('foo').ifNullThen( + refer( + 'FormatException', + ).newInstance([literalString('missing foo')]).thrown.parenthesized, + ), + equalsDart('foo ?? (throw FormatException(\'missing foo\'))'), + ); }); test('should emit an addition assigment expression', () { - expect( - refer('foo').addAssign(refer('bar')), - equalsDart('foo += bar'), - ); + expect(refer('foo').addAssign(refer('bar')), equalsDart('foo += bar')); }); test('should emit a subtraction assigment expression', () { - expect( - refer('foo').subtractAssign(refer('bar')), - equalsDart('foo -= bar'), - ); + expect(refer('foo').subtractAssign(refer('bar')), equalsDart('foo -= bar')); }); test('should emit a multiplication assigment expression', () { - expect( - refer('foo').multiplyAssign(refer('bar')), - equalsDart('foo *= bar'), - ); + expect(refer('foo').multiplyAssign(refer('bar')), equalsDart('foo *= bar')); }); test('should emit a division assigment expression', () { - expect( - refer('foo').divideAssign(refer('bar')), - equalsDart('foo /= bar'), - ); + expect(refer('foo').divideAssign(refer('bar')), equalsDart('foo /= bar')); }); test('should emit an int division assigment expression', () { diff --git a/pkgs/code_builder/test/specs/code/statement_test.dart b/pkgs/code_builder/test/specs/code/statement_test.dart index cd3d53afc..0b16ac6c1 100644 --- a/pkgs/code_builder/test/specs/code/statement_test.dart +++ b/pkgs/code_builder/test/specs/code/statement_test.dart @@ -42,15 +42,18 @@ void main() { test('should emit a block of code with lazily invoked generators', () { expect( - Method((b) => b - ..name = 'main' - ..body = Block.of([ - const Code('if ('), - lazyCode(() => refer('foo').code), - const Code(') {'), - refer('print')([literalTrue]).statement, - const Code('}'), - ])), + Method( + (b) => + b + ..name = 'main' + ..body = Block.of([ + const Code('if ('), + lazyCode(() => refer('foo').code), + const Code(') {'), + refer('print')([literalTrue]).statement, + const Code('}'), + ]), + ), equalsDart(r''' main() { if (foo) { diff --git a/pkgs/code_builder/test/specs/enum_test.dart b/pkgs/code_builder/test/specs/enum_test.dart index 3a8238a52..61a2cf4e6 100644 --- a/pkgs/code_builder/test/specs/enum_test.dart +++ b/pkgs/code_builder/test/specs/enum_test.dart @@ -12,58 +12,77 @@ void main() { test('should create an enum', () { expect( - Enum((b) => b - ..name = 'E' - ..values.addAll([ - EnumValue((b) => b..name = 'a'), - EnumValue((b) => b..name = 'b'), - ])), - equalsDart(r''' + Enum( + (b) => + b + ..name = 'E' + ..values.addAll([ + EnumValue((b) => b..name = 'a'), + EnumValue((b) => b..name = 'b'), + ]), + ), + equalsDart(r''' enum E { a, b } - ''')); + '''), + ); }); test('should create an enum with annotations', () { expect( - Enum((b) => b - ..annotations.addAll([ - refer('deprecated'), - refer('Deprecated').call([literalString('This is an old enum')]) - ]) - ..name = 'V' - ..values.addAll([ - EnumValue((b) => b..name = 'x'), - ])), - equalsDart(r''' + Enum( + (b) => + b + ..annotations.addAll([ + refer('deprecated'), + refer( + 'Deprecated', + ).call([literalString('This is an old enum')]), + ]) + ..name = 'V' + ..values.addAll([EnumValue((b) => b..name = 'x')]), + ), + equalsDart(r''' @deprecated @Deprecated('This is an old enum') enum V { x } - ''')); + '''), + ); }); test('should create an enum with annotated values', () { expect( - Enum((b) => b - ..name = 'Status' - ..values.addAll([ - EnumValue((b) => b - ..name = 'okay' - ..annotations.addAll([ - refer('deprecated'), - refer('Deprecated').call([literalString('use Good instead')]), - ])), - EnumValue((b) => b - ..name = 'good' - ..annotations.addAll([ - refer('JsonKey').call([literalString('good')]) - ])), - ])), - equalsDart(r''' + Enum( + (b) => + b + ..name = 'Status' + ..values.addAll([ + EnumValue( + (b) => + b + ..name = 'okay' + ..annotations.addAll([ + refer('deprecated'), + refer( + 'Deprecated', + ).call([literalString('use Good instead')]), + ]), + ), + EnumValue( + (b) => + b + ..name = 'good' + ..annotations.addAll([ + refer('JsonKey').call([literalString('good')]), + ]), + ), + ]), + ), + equalsDart(r''' enum Status { @deprecated @Deprecated('use Good instead') @@ -71,51 +90,66 @@ void main() { @JsonKey('good') good } - ''')); + '''), + ); }); test('should create an enum which mixes in and implements specs', () { - final myEnum = Enum((b) => b - ..name = 'MyEnum' - ..implements.addAll(const [ - Reference('InterfaceA'), - Reference('InterfaceB'), - ]) - ..mixins.addAll(const [ - Reference('Mixin1'), - Reference('Mixin2'), - ]) - ..values.addAll([ - EnumValue((v) => v..name = 'a'), - EnumValue((v) => v..name = 'b'), - EnumValue((v) => v..name = 'c'), - ])); - expect(myEnum, equalsDart(''' + final myEnum = Enum( + (b) => + b + ..name = 'MyEnum' + ..implements.addAll(const [ + Reference('InterfaceA'), + Reference('InterfaceB'), + ]) + ..mixins.addAll(const [Reference('Mixin1'), Reference('Mixin2')]) + ..values.addAll([ + EnumValue((v) => v..name = 'a'), + EnumValue((v) => v..name = 'b'), + EnumValue((v) => v..name = 'c'), + ]), + ); + expect( + myEnum, + equalsDart(''' enum MyEnum with Mixin1, Mixin2 implements InterfaceA, InterfaceB { a, b, c } - ''')); + '''), + ); }); test('should create an enum which targets a named constructor', () { - final myEnum = Enum((b) => b - ..name = 'MyEnum' - ..constructors.addAll([ - Constructor((c) => c..constant = true), - Constructor((c) => c - ..constant = true - ..name = 'named'), - ]) - ..values.addAll([ - EnumValue((v) => v..name = 'a'), - EnumValue((v) => v - ..name = 'b' - ..constructorName = 'named'), - EnumValue((v) => v..name = 'c'), - ])); - expect(myEnum, equalsDart(''' + final myEnum = Enum( + (b) => + b + ..name = 'MyEnum' + ..constructors.addAll([ + Constructor((c) => c..constant = true), + Constructor( + (c) => + c + ..constant = true + ..name = 'named', + ), + ]) + ..values.addAll([ + EnumValue((v) => v..name = 'a'), + EnumValue( + (v) => + v + ..name = 'b' + ..constructorName = 'named', + ), + EnumValue((v) => v..name = 'c'), + ]), + ); + expect( + myEnum, + equalsDart(''' enum MyEnum { a, b.named(), @@ -125,29 +159,39 @@ void main() { const MyEnum.named(); } - ''')); + '''), + ); }); test('should create an enum which targets a redirecting constructor', () { - final myEnum = Enum((b) => b - ..name = 'MyEnum' - ..constructors.addAll([ - Constructor((c) => c..constant = true), - Constructor((c) => c - ..constant = true - ..name = 'redirect' - ..initializers.add( - refer('this').call([]).code, - )), - ]) - ..values.addAll([ - EnumValue((v) => v..name = 'a'), - EnumValue((v) => v - ..name = 'b' - ..constructorName = 'redirect'), - EnumValue((v) => v..name = 'c'), - ])); - expect(myEnum, equalsDart(''' + final myEnum = Enum( + (b) => + b + ..name = 'MyEnum' + ..constructors.addAll([ + Constructor((c) => c..constant = true), + Constructor( + (c) => + c + ..constant = true + ..name = 'redirect' + ..initializers.add(refer('this').call([]).code), + ), + ]) + ..values.addAll([ + EnumValue((v) => v..name = 'a'), + EnumValue( + (v) => + v + ..name = 'b' + ..constructorName = 'redirect', + ), + EnumValue((v) => v..name = 'c'), + ]), + ); + expect( + myEnum, + equalsDart(''' enum MyEnum { a, b.redirect(), @@ -157,43 +201,65 @@ void main() { const MyEnum.redirect() : this(); } - ''')); + '''), + ); }); - test('should create an enum which targets a redirecting factory constructor', - () { - final myEnum = Enum((b) => b - ..name = 'MyEnum' - ..constructors.addAll([ - Constructor((c) => c..constant = true), - Constructor((c) => c - ..constant = true - ..factory = true - ..name = 'redirect' - ..redirect = refer('MyOtherEnum.named') - ..optionalParameters.addAll([ - Parameter((p) => p - ..type = refer('int?') - ..name = 'myInt'), - Parameter((p) => p - ..type = refer('String?') - ..name = 'myString') - ])) - ]) - ..values.addAll([ - EnumValue((v) => v..name = 'a'), - EnumValue((v) => v - ..name = 'b' - ..constructorName = 'redirect' - ..arguments.addAll([ - literalNum(1), - literalString('abc'), - ])), - EnumValue((v) => v - ..name = 'c' - ..constructorName = 'redirect'), - ])); - expect(myEnum, equalsDart(''' + test( + 'should create an enum which targets a redirecting factory constructor', + () { + final myEnum = Enum( + (b) => + b + ..name = 'MyEnum' + ..constructors.addAll([ + Constructor((c) => c..constant = true), + Constructor( + (c) => + c + ..constant = true + ..factory = true + ..name = 'redirect' + ..redirect = refer('MyOtherEnum.named') + ..optionalParameters.addAll([ + Parameter( + (p) => + p + ..type = refer('int?') + ..name = 'myInt', + ), + Parameter( + (p) => + p + ..type = refer('String?') + ..name = 'myString', + ), + ]), + ), + ]) + ..values.addAll([ + EnumValue((v) => v..name = 'a'), + EnumValue( + (v) => + v + ..name = 'b' + ..constructorName = 'redirect' + ..arguments.addAll([ + literalNum(1), + literalString('abc'), + ]), + ), + EnumValue( + (v) => + v + ..name = 'c' + ..constructorName = 'redirect', + ), + ]), + ); + expect( + myEnum, + equalsDart(''' enum MyEnum { a, b.redirect(1, 'abc'), @@ -206,43 +272,67 @@ void main() { String? myString, ]) = MyOtherEnum.named; } - ''')); - }); + '''), + ); + }, + ); test('should create an enum which targets an unnamed constructor', () { - final myEnum = Enum((b) => b - ..name = 'MyEnum' - ..constructors.add(Constructor((c) => c - ..constant = true - ..optionalParameters.addAll([ - Parameter((p) => p - ..toThis = true - ..name = 'myInt'), - Parameter((p) => p - ..toThis = true - ..name = 'myString') - ]))) - ..fields.addAll([ - Field((f) => f - ..modifier = FieldModifier.final$ - ..type = refer('int?') - ..name = 'myInt'), - Field((f) => f - ..modifier = FieldModifier.final$ - ..type = refer('String?') - ..name = 'myString') - ]) - ..values.addAll([ - EnumValue((v) => v..name = 'a'), - EnumValue((v) => v - ..name = 'b' - ..arguments.addAll([ - literalNum(1), - literalString('abc'), - ])), - EnumValue((v) => v..name = 'c'), - ])); - expect(myEnum, equalsDart(''' + final myEnum = Enum( + (b) => + b + ..name = 'MyEnum' + ..constructors.add( + Constructor( + (c) => + c + ..constant = true + ..optionalParameters.addAll([ + Parameter( + (p) => + p + ..toThis = true + ..name = 'myInt', + ), + Parameter( + (p) => + p + ..toThis = true + ..name = 'myString', + ), + ]), + ), + ) + ..fields.addAll([ + Field( + (f) => + f + ..modifier = FieldModifier.final$ + ..type = refer('int?') + ..name = 'myInt', + ), + Field( + (f) => + f + ..modifier = FieldModifier.final$ + ..type = refer('String?') + ..name = 'myString', + ), + ]) + ..values.addAll([ + EnumValue((v) => v..name = 'a'), + EnumValue( + (v) => + v + ..name = 'b' + ..arguments.addAll([literalNum(1), literalString('abc')]), + ), + EnumValue((v) => v..name = 'c'), + ]), + ); + expect( + myEnum, + equalsDart(''' enum MyEnum { a, b(1, 'abc'), @@ -257,39 +347,67 @@ void main() { final String? myString; } - ''')); + '''), + ); }); test('should create an enum with generics', () { - final myEnum = Enum((b) => b - ..name = 'MyEnum' - ..types.add(const Reference('T')) - ..constructors.add(Constructor((c) => c - ..constant = true - ..requiredParameters.add(Parameter((p) => p - ..toThis = true - ..name = 'value')))) - ..fields.add( - Field((f) => f - ..modifier = FieldModifier.final$ - ..type = refer('T') - ..name = 'value'), - ) - ..values.addAll([ - EnumValue((v) => v - ..name = 'a' - ..types.add(const Reference('int')) - ..arguments.add(literalNum(123))), - EnumValue((v) => v - ..name = 'b' - ..types.add(const Reference('String')) - ..arguments.add(literalString('abc'))), - EnumValue((v) => v - ..name = 'c' - ..types.add(const Reference('MyEnum')) - ..arguments.add(refer('MyEnum').property('a'))), - ])); - expect(myEnum, equalsDart(''' + final myEnum = Enum( + (b) => + b + ..name = 'MyEnum' + ..types.add(const Reference('T')) + ..constructors.add( + Constructor( + (c) => + c + ..constant = true + ..requiredParameters.add( + Parameter( + (p) => + p + ..toThis = true + ..name = 'value', + ), + ), + ), + ) + ..fields.add( + Field( + (f) => + f + ..modifier = FieldModifier.final$ + ..type = refer('T') + ..name = 'value', + ), + ) + ..values.addAll([ + EnumValue( + (v) => + v + ..name = 'a' + ..types.add(const Reference('int')) + ..arguments.add(literalNum(123)), + ), + EnumValue( + (v) => + v + ..name = 'b' + ..types.add(const Reference('String')) + ..arguments.add(literalString('abc')), + ), + EnumValue( + (v) => + v + ..name = 'c' + ..types.add(const Reference('MyEnum')) + ..arguments.add(refer('MyEnum').property('a')), + ), + ]), + ); + expect( + myEnum, + equalsDart(''' enum MyEnum { a(123), b('abc'), @@ -299,35 +417,57 @@ void main() { final T value; } - ''')); + '''), + ); }); test('should create an enum with fields', () { - final myEnum = Enum((b) => b - ..name = 'MyEnum' - ..constructors.add(Constructor((c) => c - ..constant = true - ..optionalParameters.add(Parameter((p) => p - ..toThis = true - ..name = 'myInt')))) - ..fields.addAll([ - Field((f) => f - ..modifier = FieldModifier.final$ - ..type = refer('int?') - ..name = 'myInt'), - Field((f) => f - ..static = true - ..modifier = FieldModifier.constant - ..type = refer('String') - ..name = 'myString' - ..assignment = literalString('abc').code), - ]) - ..values.addAll([ - EnumValue((v) => v..name = 'a'), - EnumValue((v) => v..name = 'b'), - EnumValue((v) => v..name = 'c'), - ])); - expect(myEnum, equalsDart(''' + final myEnum = Enum( + (b) => + b + ..name = 'MyEnum' + ..constructors.add( + Constructor( + (c) => + c + ..constant = true + ..optionalParameters.add( + Parameter( + (p) => + p + ..toThis = true + ..name = 'myInt', + ), + ), + ), + ) + ..fields.addAll([ + Field( + (f) => + f + ..modifier = FieldModifier.final$ + ..type = refer('int?') + ..name = 'myInt', + ), + Field( + (f) => + f + ..static = true + ..modifier = FieldModifier.constant + ..type = refer('String') + ..name = 'myString' + ..assignment = literalString('abc').code, + ), + ]) + ..values.addAll([ + EnumValue((v) => v..name = 'a'), + EnumValue((v) => v..name = 'b'), + EnumValue((v) => v..name = 'c'), + ]), + ); + expect( + myEnum, + equalsDart(''' enum MyEnum { a, b, @@ -339,34 +479,46 @@ void main() { static const String myString = 'abc'; } - ''')); + '''), + ); }); test('should create an enum with methods', () { - final myEnum = Enum((b) => b - ..name = 'MyEnum' - ..methods.addAll([ - Method((m) => m - ..returns = refer('int') - ..type = MethodType.getter - ..name = 'myInt' - ..body = literalNum(123).code), - Method((m) => m - ..returns = refer('Iterable') - ..name = 'myStrings' - ..modifier = MethodModifier.syncStar - ..body = Block.of(const [ - Code("yield 'a';"), - Code("yield 'b';"), - Code("yield 'c';"), - ])) - ]) - ..values.addAll([ - EnumValue((v) => v..name = 'a'), - EnumValue((v) => v..name = 'b'), - EnumValue((v) => v..name = 'c'), - ])); - expect(myEnum, equalsDart(''' + final myEnum = Enum( + (b) => + b + ..name = 'MyEnum' + ..methods.addAll([ + Method( + (m) => + m + ..returns = refer('int') + ..type = MethodType.getter + ..name = 'myInt' + ..body = literalNum(123).code, + ), + Method( + (m) => + m + ..returns = refer('Iterable') + ..name = 'myStrings' + ..modifier = MethodModifier.syncStar + ..body = Block.of(const [ + Code("yield 'a';"), + Code("yield 'b';"), + Code("yield 'c';"), + ]), + ), + ]) + ..values.addAll([ + EnumValue((v) => v..name = 'a'), + EnumValue((v) => v..name = 'b'), + EnumValue((v) => v..name = 'c'), + ]), + ); + expect( + myEnum, + equalsDart(''' enum MyEnum { a, b, @@ -380,50 +532,75 @@ void main() { yield 'c'; } } - ''')); + '''), + ); }); - test('should create an enum which named and unnamed constructor parameters', - () { - final myEnum = Enum((b) => b - ..name = 'MyEnum' - ..constructors.add(Constructor((c) => c - ..constant = true - ..requiredParameters.addAll([ - Parameter((p) => p - ..toThis = true - ..name = 'myInt') - ]) - ..optionalParameters.addAll([ - Parameter((p) => p - ..toThis = true - ..named = true - ..required = true - ..name = 'myString') - ]))) - ..fields.addAll([ - Field((f) => f - ..modifier = FieldModifier.final$ - ..type = refer('int?') - ..name = 'myInt'), - Field((f) => f - ..modifier = FieldModifier.final$ - ..type = refer('String?') - ..name = 'myString') - ]) - ..values.addAll([ - EnumValue((v) => v..name = 'a'), - EnumValue((v) => v - ..name = 'b' - ..arguments.addAll([ - literalNum(1), - ]) - ..namedArguments.addAll({ - 'myString': literalString('abc'), - })), - EnumValue((v) => v..name = 'c'), - ])); - expect(myEnum, equalsDart(''' + test( + 'should create an enum which named and unnamed constructor parameters', + () { + final myEnum = Enum( + (b) => + b + ..name = 'MyEnum' + ..constructors.add( + Constructor( + (c) => + c + ..constant = true + ..requiredParameters.addAll([ + Parameter( + (p) => + p + ..toThis = true + ..name = 'myInt', + ), + ]) + ..optionalParameters.addAll([ + Parameter( + (p) => + p + ..toThis = true + ..named = true + ..required = true + ..name = 'myString', + ), + ]), + ), + ) + ..fields.addAll([ + Field( + (f) => + f + ..modifier = FieldModifier.final$ + ..type = refer('int?') + ..name = 'myInt', + ), + Field( + (f) => + f + ..modifier = FieldModifier.final$ + ..type = refer('String?') + ..name = 'myString', + ), + ]) + ..values.addAll([ + EnumValue((v) => v..name = 'a'), + EnumValue( + (v) => + v + ..name = 'b' + ..arguments.addAll([literalNum(1)]) + ..namedArguments.addAll({ + 'myString': literalString('abc'), + }), + ), + EnumValue((v) => v..name = 'c'), + ]), + ); + expect( + myEnum, + equalsDart(''' enum MyEnum { a, b(1, myString: 'abc'), @@ -438,6 +615,8 @@ void main() { final String? myString; } - ''')); - }); + '''), + ); + }, + ); } diff --git a/pkgs/code_builder/test/specs/extension_test.dart b/pkgs/code_builder/test/specs/extension_test.dart index b45fa6580..6a0f307bb 100644 --- a/pkgs/code_builder/test/specs/extension_test.dart +++ b/pkgs/code_builder/test/specs/extension_test.dart @@ -12,9 +12,12 @@ void main() { test('should create an extension', () { expect( - Extension((b) => b - ..name = 'Foo' - ..on = TypeReference((b) => b.symbol = 'Bar')), + Extension( + (b) => + b + ..name = 'Foo' + ..on = TypeReference((b) => b.symbol = 'Bar'), + ), equalsDart(r''' extension Foo on Bar {} '''), @@ -33,14 +36,11 @@ void main() { test('should create an extension with documentation', () { expect( Extension( - (b) => b - ..name = 'Foo' - ..on = TypeReference((b) => b.symbol = 'Bar') - ..docs.addAll( - const [ - '/// My favorite extension.', - ], - ), + (b) => + b + ..name = 'Foo' + ..on = TypeReference((b) => b.symbol = 'Bar') + ..docs.addAll(const ['/// My favorite extension.']), ), equalsDart(r''' /// My favorite extension. @@ -52,14 +52,16 @@ void main() { test('should create an extension with annotations', () { expect( Extension( - (b) => b - ..name = 'Foo' - ..on = TypeReference((b) => b.symbol = 'Bar') - ..annotations.addAll([ - refer('deprecated'), - refer('Deprecated') - .call([literalString('This is an old extension')]) - ]), + (b) => + b + ..name = 'Foo' + ..on = TypeReference((b) => b.symbol = 'Bar') + ..annotations.addAll([ + refer('deprecated'), + refer( + 'Deprecated', + ).call([literalString('This is an old extension')]), + ]), ), equalsDart(r''' @deprecated @@ -71,10 +73,13 @@ void main() { test('should create an extension with a generic type', () { expect( - Extension((b) => b - ..name = 'Foo' - ..on = TypeReference((b) => b.symbol = 'Bar') - ..types.add(refer('T'))), + Extension( + (b) => + b + ..name = 'Foo' + ..on = TypeReference((b) => b.symbol = 'Bar') + ..types.add(refer('T')), + ), equalsDart(r''' extension Foo on Bar {} '''), @@ -84,13 +89,11 @@ void main() { test('should create an extension with multiple generic types', () { expect( Extension( - (b) => b - ..name = 'Map' - ..on = TypeReference((b) => b.symbol = 'Bar') - ..types.addAll([ - refer('K'), - refer('V'), - ]), + (b) => + b + ..name = 'Map' + ..on = TypeReference((b) => b.symbol = 'Bar') + ..types.addAll([refer('K'), refer('V')]), ), equalsDart(r''' extension Map on Bar {} @@ -100,14 +103,25 @@ void main() { test('should create an extension with a bound generic type', () { expect( - Extension((b) => b - ..name = 'Foo' - ..on = TypeReference((b) => b.symbol = 'Bar') - ..types.add(TypeReference((b) => b - ..symbol = 'T' - ..bound = TypeReference((b) => b - ..symbol = 'Comparable' - ..types.add(refer('T').type))))), + Extension( + (b) => + b + ..name = 'Foo' + ..on = TypeReference((b) => b.symbol = 'Bar') + ..types.add( + TypeReference( + (b) => + b + ..symbol = 'T' + ..bound = TypeReference( + (b) => + b + ..symbol = 'Comparable' + ..types.add(refer('T').type), + ), + ), + ), + ), equalsDart(r''' extension Foo> on Bar {} '''), @@ -116,15 +130,21 @@ void main() { test('should create an extension with a method', () { expect( - Extension((b) => b - ..name = 'Foo' - ..on = TypeReference((b) => b.symbol = 'Bar') - ..methods.add(Method((b) => b - ..name = 'parseInt' - ..returns = refer('int') - ..body = Code.scope( - (a) => 'return int.parse(this);', - )))), + Extension( + (b) => + b + ..name = 'Foo' + ..on = TypeReference((b) => b.symbol = 'Bar') + ..methods.add( + Method( + (b) => + b + ..name = 'parseInt' + ..returns = refer('int') + ..body = Code.scope((a) => 'return int.parse(this);'), + ), + ), + ), equalsDart(r''' extension Foo on Bar { int parseInt() { diff --git a/pkgs/code_builder/test/specs/extension_type_test.dart b/pkgs/code_builder/test/specs/extension_type_test.dart index cc510468f..b3b942adb 100644 --- a/pkgs/code_builder/test/specs/extension_type_test.dart +++ b/pkgs/code_builder/test/specs/extension_type_test.dart @@ -12,11 +12,19 @@ void main() { test('minimum extension type', () { expect( - ExtensionType((b) => b - ..name = 'Foo' - ..representationDeclaration = RepresentationDeclaration((b) => b - ..declaredRepresentationType = TypeReference((b) => b.symbol = 'int') - ..name = 'bar')), + ExtensionType( + (b) => + b + ..name = 'Foo' + ..representationDeclaration = RepresentationDeclaration( + (b) => + b + ..declaredRepresentationType = TypeReference( + (b) => b.symbol = 'int', + ) + ..name = 'bar', + ), + ), equalsDart(r''' extension type Foo(int bar) { } '''), @@ -25,12 +33,20 @@ void main() { test('const extension type', () { expect( - ExtensionType((b) => b - ..name = 'Foo' - ..constant = true - ..representationDeclaration = RepresentationDeclaration((b) => b - ..declaredRepresentationType = TypeReference((b) => b.symbol = 'int') - ..name = 'bar')), + ExtensionType( + (b) => + b + ..name = 'Foo' + ..constant = true + ..representationDeclaration = RepresentationDeclaration( + (b) => + b + ..declaredRepresentationType = TypeReference( + (b) => b.symbol = 'int', + ) + ..name = 'bar', + ), + ), equalsDart(r''' extension type const Foo(int bar) { } '''), @@ -39,19 +55,26 @@ void main() { test('extension type with metadata', () { expect( - ExtensionType((b) => b - ..name = 'Foo' - ..representationDeclaration = RepresentationDeclaration((b) => b - ..declaredRepresentationType = TypeReference((b) => b.symbol = 'int') - ..name = 'bar') - ..docs.add( - '/// My favorite extension type.', - ) - ..annotations.addAll([ - refer('deprecated'), - refer('Deprecated') - .call([literalString('This is an old extension type')]) - ])), + ExtensionType( + (b) => + b + ..name = 'Foo' + ..representationDeclaration = RepresentationDeclaration( + (b) => + b + ..declaredRepresentationType = TypeReference( + (b) => b.symbol = 'int', + ) + ..name = 'bar', + ) + ..docs.add('/// My favorite extension type.') + ..annotations.addAll([ + refer('deprecated'), + refer( + 'Deprecated', + ).call([literalString('This is an old extension type')]), + ]), + ), equalsDart(r''' /// My favorite extension type. @deprecated @@ -63,15 +86,23 @@ void main() { test('extension type with generics', () { expect( - ExtensionType((b) => b - ..name = 'Foo' - ..types.addAll([ - TypeReference((b) => b..symbol = 'T'), - TypeReference((b) => b..symbol = 'U') - ]) - ..representationDeclaration = RepresentationDeclaration((b) => b - ..declaredRepresentationType = TypeReference((b) => b.symbol = 'T') - ..name = 'bar')), + ExtensionType( + (b) => + b + ..name = 'Foo' + ..types.addAll([ + TypeReference((b) => b..symbol = 'T'), + TypeReference((b) => b..symbol = 'U'), + ]) + ..representationDeclaration = RepresentationDeclaration( + (b) => + b + ..declaredRepresentationType = TypeReference( + (b) => b.symbol = 'T', + ) + ..name = 'bar', + ), + ), equalsDart(r''' extension type Foo(T bar) { } '''), @@ -80,14 +111,27 @@ void main() { test('extension type with generics bound', () { expect( - ExtensionType((b) => b - ..name = 'Foo' - ..types.add(TypeReference((b) => b - ..symbol = 'T' - ..bound = TypeReference((b) => b..symbol = 'num'))) - ..representationDeclaration = RepresentationDeclaration((b) => b - ..declaredRepresentationType = TypeReference((b) => b.symbol = 'T') - ..name = 'bar')), + ExtensionType( + (b) => + b + ..name = 'Foo' + ..types.add( + TypeReference( + (b) => + b + ..symbol = 'T' + ..bound = TypeReference((b) => b..symbol = 'num'), + ), + ) + ..representationDeclaration = RepresentationDeclaration( + (b) => + b + ..declaredRepresentationType = TypeReference( + (b) => b.symbol = 'T', + ) + ..name = 'bar', + ), + ), equalsDart(r''' extension type Foo(T bar) { } '''), @@ -96,12 +140,20 @@ void main() { test('extension type with named primary constructor', () { expect( - ExtensionType((b) => b - ..name = 'Foo' - ..primaryConstructorName = 'named' - ..representationDeclaration = RepresentationDeclaration((b) => b - ..declaredRepresentationType = TypeReference((b) => b.symbol = 'int') - ..name = 'bar')), + ExtensionType( + (b) => + b + ..name = 'Foo' + ..primaryConstructorName = 'named' + ..representationDeclaration = RepresentationDeclaration( + (b) => + b + ..declaredRepresentationType = TypeReference( + (b) => b.symbol = 'int', + ) + ..name = 'bar', + ), + ), equalsDart(r''' extension type Foo.named(int bar) { } '''), @@ -110,19 +162,28 @@ void main() { test('extension type with metadata on field', () { expect( - ExtensionType((b) => b - ..name = 'Foo' - ..representationDeclaration = RepresentationDeclaration((b) => b - ..declaredRepresentationType = TypeReference((b) => b.symbol = 'int') - ..name = 'bar' - ..docs.add( - '/// My favorite representation declaration.', - ) - ..annotations.addAll([ - refer('deprecated'), - refer('Deprecated').call( - [literalString('This is an old representation declaration')]) - ]))), + ExtensionType( + (b) => + b + ..name = 'Foo' + ..representationDeclaration = RepresentationDeclaration( + (b) => + b + ..declaredRepresentationType = TypeReference( + (b) => b.symbol = 'int', + ) + ..name = 'bar' + ..docs.add('/// My favorite representation declaration.') + ..annotations.addAll([ + refer('deprecated'), + refer('Deprecated').call([ + literalString( + 'This is an old representation declaration', + ), + ]), + ]), + ), + ), equalsDart(r''' extension type Foo(/// My favorite representation declaration. @deprecated @@ -134,12 +195,20 @@ void main() { test('extension type with implements', () { expect( - ExtensionType((b) => b - ..name = 'Foo' - ..implements.add(TypeReference((b) => b.symbol = 'num')) - ..representationDeclaration = RepresentationDeclaration((b) => b - ..declaredRepresentationType = TypeReference((b) => b.symbol = 'int') - ..name = 'bar')), + ExtensionType( + (b) => + b + ..name = 'Foo' + ..implements.add(TypeReference((b) => b.symbol = 'num')) + ..representationDeclaration = RepresentationDeclaration( + (b) => + b + ..declaredRepresentationType = TypeReference( + (b) => b.symbol = 'int', + ) + ..name = 'bar', + ), + ), equalsDart(r''' extension type Foo(int bar) implements num { } '''), @@ -148,15 +217,23 @@ void main() { test('extension type with multiple implements', () { expect( - ExtensionType((b) => b - ..name = 'Foo' - ..implements.addAll([ - TypeReference((b) => b.symbol = 'num'), - TypeReference((b) => b.symbol = 'Object') - ]) - ..representationDeclaration = RepresentationDeclaration((b) => b - ..declaredRepresentationType = TypeReference((b) => b.symbol = 'int') - ..name = 'bar')), + ExtensionType( + (b) => + b + ..name = 'Foo' + ..implements.addAll([ + TypeReference((b) => b.symbol = 'num'), + TypeReference((b) => b.symbol = 'Object'), + ]) + ..representationDeclaration = RepresentationDeclaration( + (b) => + b + ..declaredRepresentationType = TypeReference( + (b) => b.symbol = 'int', + ) + ..name = 'bar', + ), + ), equalsDart(r''' extension type Foo(int bar) implements num,Object { } '''), @@ -165,24 +242,49 @@ void main() { test('extension type with constructors', () { expect( - ExtensionType((b) => b - ..name = 'Foo' - ..primaryConstructorName = '_' - ..representationDeclaration = RepresentationDeclaration((b) => b - ..declaredRepresentationType = TypeReference((b) => b.symbol = 'int') - ..name = 'bar') - ..constructors.addAll([ - Constructor((b) => b.requiredParameters.add(Parameter((b) => b - ..toThis = true - ..name = 'bar'))), - Constructor((b) => b - ..name = 'named' - ..factory = true - ..requiredParameters.add(Parameter((b) => b - ..type = TypeReference((b) => b.symbol = 'int') - ..name = 'baz')) - ..body = const Code('return Foo(baz);')) - ])), + ExtensionType( + (b) => + b + ..name = 'Foo' + ..primaryConstructorName = '_' + ..representationDeclaration = RepresentationDeclaration( + (b) => + b + ..declaredRepresentationType = TypeReference( + (b) => b.symbol = 'int', + ) + ..name = 'bar', + ) + ..constructors.addAll([ + Constructor( + (b) => b.requiredParameters.add( + Parameter( + (b) => + b + ..toThis = true + ..name = 'bar', + ), + ), + ), + Constructor( + (b) => + b + ..name = 'named' + ..factory = true + ..requiredParameters.add( + Parameter( + (b) => + b + ..type = TypeReference( + (b) => b.symbol = 'int', + ) + ..name = 'baz', + ), + ) + ..body = const Code('return Foo(baz);'), + ), + ]), + ), equalsDart(r''' extension type Foo._(int bar) { Foo(this.bar); @@ -197,15 +299,28 @@ void main() { test('extension type with external field', () { expect( - ExtensionType((b) => b - ..name = 'Foo' - ..representationDeclaration = RepresentationDeclaration((b) => b - ..declaredRepresentationType = TypeReference((b) => b.symbol = 'int') - ..name = 'bar') - ..fields.add(Field((b) => b - ..external = true - ..type = TypeReference((b) => b.symbol = 'int') - ..name = 'property'))), + ExtensionType( + (b) => + b + ..name = 'Foo' + ..representationDeclaration = RepresentationDeclaration( + (b) => + b + ..declaredRepresentationType = TypeReference( + (b) => b.symbol = 'int', + ) + ..name = 'bar', + ) + ..fields.add( + Field( + (b) => + b + ..external = true + ..type = TypeReference((b) => b.symbol = 'int') + ..name = 'property', + ), + ), + ), equalsDart(r''' extension type Foo(int bar) { external int property; @@ -216,23 +331,37 @@ void main() { test('extension type with methods', () { expect( - ExtensionType((b) => b - ..name = 'Foo' - ..representationDeclaration = RepresentationDeclaration((b) => b - ..declaredRepresentationType = TypeReference((b) => b.symbol = 'int') - ..name = 'bar') - ..methods.addAll([ - Method((b) => b - ..type = MethodType.getter - ..returns = TypeReference((b) => b.symbol = 'int') - ..name = 'value' - ..body = const Code('return this.bar;')), - Method((b) => b - ..returns = TypeReference((b) => b.symbol = 'int') - ..name = 'getValue' - ..lambda = true - ..body = const Code('this.bar')) - ])), + ExtensionType( + (b) => + b + ..name = 'Foo' + ..representationDeclaration = RepresentationDeclaration( + (b) => + b + ..declaredRepresentationType = TypeReference( + (b) => b.symbol = 'int', + ) + ..name = 'bar', + ) + ..methods.addAll([ + Method( + (b) => + b + ..type = MethodType.getter + ..returns = TypeReference((b) => b.symbol = 'int') + ..name = 'value' + ..body = const Code('return this.bar;'), + ), + Method( + (b) => + b + ..returns = TypeReference((b) => b.symbol = 'int') + ..name = 'getValue' + ..lambda = true + ..body = const Code('this.bar'), + ), + ]), + ), equalsDart(r''' extension type Foo(int bar) { int get value { return this.bar; } diff --git a/pkgs/code_builder/test/specs/field_test.dart b/pkgs/code_builder/test/specs/field_test.dart index 0b8d6d905..a887fe77e 100644 --- a/pkgs/code_builder/test/specs/field_test.dart +++ b/pkgs/code_builder/test/specs/field_test.dart @@ -21,9 +21,12 @@ void main() { test('should create a typed field', () { expect( - Field((b) => b - ..name = 'foo' - ..type = refer('String')), + Field( + (b) => + b + ..name = 'foo' + ..type = refer('String'), + ), equalsDart(r''' String foo; '''), @@ -32,9 +35,12 @@ void main() { test('should create a final field', () { expect( - Field((b) => b - ..name = 'foo' - ..modifier = FieldModifier.final$), + Field( + (b) => + b + ..name = 'foo' + ..modifier = FieldModifier.final$, + ), equalsDart(r''' final foo; '''), @@ -43,9 +49,12 @@ void main() { test('should create a constant field', () { expect( - Field((b) => b - ..name = 'foo' - ..modifier = FieldModifier.constant), + Field( + (b) => + b + ..name = 'foo' + ..modifier = FieldModifier.constant, + ), equalsDart(r''' const foo; '''), @@ -54,9 +63,12 @@ void main() { test('should create a late field if using null-safety', () { expect( - Field((b) => b - ..late = true - ..name = 'foo'), + Field( + (b) => + b + ..late = true + ..name = 'foo', + ), equalsDart(r''' late var foo; ''', DartEmitter(useNullSafetySyntax: true)), @@ -65,9 +77,12 @@ void main() { test('should not create a late field if not using null-safety', () { expect( - Field((b) => b - ..late = true - ..name = 'foo'), + Field( + (b) => + b + ..late = true + ..name = 'foo', + ), equalsDart(r''' var foo; '''), @@ -76,10 +91,13 @@ void main() { test('should create a static late field', () { expect( - Field((b) => b - ..static = true - ..late = true - ..name = 'foo'), + Field( + (b) => + b + ..static = true + ..late = true + ..name = 'foo', + ), equalsDart(r''' static late var foo; ''', DartEmitter(useNullSafetySyntax: true)), @@ -88,9 +106,12 @@ void main() { test('should create a field with an assignment', () { expect( - Field((b) => b - ..name = 'foo' - ..assignment = const Code('1')), + Field( + (b) => + b + ..name = 'foo' + ..assignment = const Code('1'), + ), equalsDart(r''' var foo = 1; '''), @@ -99,11 +120,14 @@ void main() { test('should create a external field', () { expect( - Field((b) => b - ..name = 'value' - ..external = true - ..type = refer('double') - ..annotations.addAll([refer('Float').call([])])), + Field( + (b) => + b + ..name = 'value' + ..external = true + ..type = refer('double') + ..annotations.addAll([refer('Float').call([])]), + ), equalsDart(r''' @Float() external double value; @@ -113,12 +137,15 @@ void main() { test('should create a late static field', () { expect( - Field((b) => b - ..name = 'value' - ..static = true - ..late = true - ..type = refer('String') - ..annotations.addAll([refer('JS').call([])])), + Field( + (b) => + b + ..name = 'value' + ..static = true + ..late = true + ..type = refer('String') + ..annotations.addAll([refer('JS').call([])]), + ), equalsDart(r''' @JS() static late String value; @@ -128,12 +155,15 @@ void main() { test('should create an external static field', () { expect( - Field((b) => b - ..name = 'value' - ..external = true - ..static = true - ..type = refer('double') - ..annotations.addAll([refer('JS').call([])])), + Field( + (b) => + b + ..name = 'value' + ..external = true + ..static = true + ..type = refer('double') + ..annotations.addAll([refer('JS').call([])]), + ), equalsDart(r''' @JS() external static double value; diff --git a/pkgs/code_builder/test/specs/library_test.dart b/pkgs/code_builder/test/specs/library_test.dart index 8ea4c5811..426f44227 100644 --- a/pkgs/code_builder/test/specs/library_test.dart +++ b/pkgs/code_builder/test/specs/library_test.dart @@ -16,11 +16,10 @@ void main() { test('should emit a source file with leading line comments', () { expect( Library( - (b) => b - ..comments.add('Generated by foo.') - ..body.add( - Class((b) => b..name = 'Foo'), - ), + (b) => + b + ..comments.add('Generated by foo.') + ..body.add(Class((b) => b..name = 'Foo')), ), equalsDart(r''' // Generated by foo. @@ -33,15 +32,14 @@ void main() { test('should emit a source file with multiple leading comments', () { expect( Library( - (b) => b - ..comments.addAll([ - 'Generated by foo!', - '', - 'Avoid editing by hand.', - ]) - ..body.add( - Class((b) => b..name = 'Foo'), - ), + (b) => + b + ..comments.addAll([ + 'Generated by foo!', + '', + 'Avoid editing by hand.', + ]) + ..body.add(Class((b) => b..name = 'Foo')), ), equalsDart(r''' // Generated by foo! @@ -56,11 +54,10 @@ void main() { test('should emit a source file with a generated-by comment', () { expect( Library( - (b) => b - ..generatedByComment = 'Generated by fooBar.' - ..body.add( - Class((b) => b..name = 'Foo'), - ), + (b) => + b + ..generatedByComment = 'Generated by fooBar.' + ..body.add(Class((b) => b..name = 'Foo')), ), equalsDart(r''' // Generated by fooBar. @@ -73,11 +70,10 @@ void main() { test('should emit a source file with ignore comments', () { expect( Library( - (b) => b - ..ignoreForFile.add('sort_constructors_first') - ..body.add( - Class((b) => b..name = 'Foo'), - ), + (b) => + b + ..ignoreForFile.add('sort_constructors_first') + ..body.add(Class((b) => b..name = 'Foo')), ), equalsDart(r''' // ignore_for_file: sort_constructors_first @@ -90,16 +86,15 @@ void main() { test('should emit a source file with multiple, sorted ignore comments', () { expect( Library( - (b) => b - ..ignoreForFile.addAll([ - 'type=lint', - 'sort_constructors_first', - 'implementation_imports', - 'file_names', - ]) - ..body.add( - Class((b) => b..name = 'Foo'), - ), + (b) => + b + ..ignoreForFile.addAll([ + 'type=lint', + 'sort_constructors_first', + 'implementation_imports', + 'file_names', + ]) + ..body.add(Class((b) => b..name = 'Foo')), ), equalsDart(r''' // ignore_for_file: file_names, implementation_imports, sort_constructors_first @@ -110,19 +105,19 @@ void main() { ); }); - test('should emit with line comments, generated-by, and ignore-for-file', - () { - expect( - Library( - (b) => b - ..comments.add('Generic copyright statement.') - ..generatedByComment = 'Generated by fooBar.' - ..ignoreForFile.add('sort_constructors_first') - ..body.add( - Class((b) => b..name = 'Foo'), - ), - ), - equalsDart(r''' + test( + 'should emit with line comments, generated-by, and ignore-for-file', + () { + expect( + Library( + (b) => + b + ..comments.add('Generic copyright statement.') + ..generatedByComment = 'Generated by fooBar.' + ..ignoreForFile.add('sort_constructors_first') + ..body.add(Class((b) => b..name = 'Foo')), + ), + equalsDart(r''' // Generic copyright statement. // Generated by fooBar. @@ -131,17 +126,26 @@ void main() { class Foo { } ''', DartEmitter(allocator: Allocator())), - ); - }); + ); + }, + ); test('should emit a source file with manual imports', () { expect( - Library((b) => b - ..directives.add(Directive.import('dart:collection')) - ..body.add(Field((b) => b - ..name = 'test' - ..modifier = FieldModifier.final$ - ..assignment = $LinkedHashMap.newInstance([]).code))), + Library( + (b) => + b + ..directives.add(Directive.import('dart:collection')) + ..body.add( + Field( + (b) => + b + ..name = 'test' + ..modifier = FieldModifier.final$ + ..assignment = $LinkedHashMap.newInstance([]).code, + ), + ), + ), equalsDart(r''' import 'dart:collection'; @@ -153,13 +157,11 @@ void main() { test('should emit a source file with a deferred import', () { expect( Library( - (b) => b - ..directives.add( - Directive.importDeferredAs( - 'package:foo/foo.dart', - 'foo', - ), - ), + (b) => + b + ..directives.add( + Directive.importDeferredAs('package:foo/foo.dart', 'foo'), + ), ), equalsDart(r''' import 'package:foo/foo.dart' deferred as foo; @@ -170,13 +172,14 @@ void main() { test('should emit a source file with a "show" combinator', () { expect( Library( - (b) => b - ..directives.add( - Directive.import( - 'package:foo/foo.dart', - show: ['Foo', 'Bar'], - ), - ), + (b) => + b + ..directives.add( + Directive.import( + 'package:foo/foo.dart', + show: ['Foo', 'Bar'], + ), + ), ), equalsDart(r''' import 'package:foo/foo.dart' show Foo, Bar; @@ -187,13 +190,14 @@ void main() { test('should emit a source file with a "hide" combinator', () { expect( Library( - (b) => b - ..directives.add( - Directive.import( - 'package:foo/foo.dart', - hide: ['Foo', 'Bar'], - ), - ), + (b) => + b + ..directives.add( + Directive.import( + 'package:foo/foo.dart', + hide: ['Foo', 'Bar'], + ), + ), ), equalsDart(r''' import 'package:foo/foo.dart' hide Foo, Bar; @@ -203,11 +207,21 @@ void main() { test('should emit a source file with allocation', () { expect( - Library((b) => b - ..body.add(Field((b) => b - ..name = 'test' - ..modifier = FieldModifier.final$ - ..assignment = Code.scope((a) => '${a($LinkedHashMap)}()')))), + Library( + (b) => + b + ..body.add( + Field( + (b) => + b + ..name = 'test' + ..modifier = FieldModifier.final$ + ..assignment = Code.scope( + (a) => '${a($LinkedHashMap)}()', + ), + ), + ), + ), equalsDart(r''' import 'dart:collection'; @@ -218,11 +232,21 @@ void main() { test('should emit a source file with allocation + prefixing', () { expect( - Library((b) => b - ..body.add(Field((b) => b - ..name = 'test' - ..modifier = FieldModifier.final$ - ..assignment = Code.scope((a) => '${a($LinkedHashMap)}()')))), + Library( + (b) => + b + ..body.add( + Field( + (b) => + b + ..name = 'test' + ..modifier = FieldModifier.final$ + ..assignment = Code.scope( + (a) => '${a($LinkedHashMap)}()', + ), + ), + ), + ), equalsDart(r''' // ignore_for_file: no_leading_underscores_for_library_prefixes import 'dart:collection' as _i1; @@ -234,12 +258,7 @@ void main() { test('should emit a source file with part directives', () { expect( - Library( - (b) => b - ..directives.add( - Directive.part('test.g.dart'), - ), - ), + Library((b) => b..directives.add(Directive.part('test.g.dart'))), equalsDart(r''' part 'test.g.dart'; ''', DartEmitter()), @@ -248,12 +267,7 @@ void main() { test('should emit a source file with part of directives', () { expect( - Library( - (b) => b - ..directives.add( - Directive.partOf('test.dart'), - ), - ), + Library((b) => b..directives.add(Directive.partOf('test.dart'))), equalsDart(r''' part of 'test.dart'; ''', DartEmitter()), @@ -263,11 +277,10 @@ void main() { test('should emit a source file with annotations', () { expect( Library( - (b) => b - ..name = 'js_interop' - ..annotations.add( - refer('JS', 'package:js/js.dart').call([]), - ), + (b) => + b + ..name = 'js_interop' + ..annotations.add(refer('JS', 'package:js/js.dart').call([])), ), equalsDart(r''' @JS() @@ -280,10 +293,7 @@ void main() { test('should emit an unnamed library source file with annotations', () { expect( Library( - (b) => b - ..annotations.add( - refer('JS', 'package:js/js.dart').call([]), - ), + (b) => b..annotations.add(refer('JS', 'package:js/js.dart').call([])), ), equalsDart(r''' @JS() @@ -295,14 +305,7 @@ void main() { test('should emit an unnamed library source file with documentation', () { expect( - Library( - (b) => b - ..docs.addAll( - const [ - '/// My favorite library.', - ], - ), - ), + Library((b) => b..docs.addAll(const ['/// My favorite library.'])), equalsDart(r''' /// My favorite library. library; diff --git a/pkgs/code_builder/test/specs/method_test.dart b/pkgs/code_builder/test/specs/method_test.dart index 5621bc52c..0a3362110 100644 --- a/pkgs/code_builder/test/specs/method_test.dart +++ b/pkgs/code_builder/test/specs/method_test.dart @@ -21,10 +21,13 @@ void main() { test('should create an async method', () { expect( - Method((b) => b - ..name = 'foo' - ..modifier = MethodModifier.async - ..body = literalNull.code), + Method( + (b) => + b + ..name = 'foo' + ..modifier = MethodModifier.async + ..body = literalNull.code, + ), equalsDart(r''' foo() async => null '''), @@ -33,10 +36,13 @@ void main() { test('should create an async* method', () { expect( - Method((b) => b - ..name = 'foo' - ..modifier = MethodModifier.asyncStar - ..body = literalNull.code), + Method( + (b) => + b + ..name = 'foo' + ..modifier = MethodModifier.asyncStar + ..body = literalNull.code, + ), equalsDart(r''' foo() async* => null '''), @@ -45,10 +51,13 @@ void main() { test('should create an sync* method', () { expect( - Method((b) => b - ..name = 'foo' - ..modifier = MethodModifier.syncStar - ..body = literalNull.code), + Method( + (b) => + b + ..name = 'foo' + ..modifier = MethodModifier.syncStar + ..body = literalNull.code, + ), equalsDart(r''' foo() sync* => null '''), @@ -57,10 +66,13 @@ void main() { test('should create a lambda method implicitly', () { expect( - Method((b) => b - ..name = 'returnsTrue' - ..returns = refer('bool') - ..body = literalTrue.code), + Method( + (b) => + b + ..name = 'returnsTrue' + ..returns = refer('bool') + ..body = literalTrue.code, + ), equalsDart(r''' bool returnsTrue() => true '''), @@ -69,10 +81,13 @@ void main() { test('should create a lambda method if the value is cast', () { expect( - Method((b) => b - ..name = 'returnsCastedValue' - ..returns = refer('Foo') - ..body = refer('bar').asA(refer('Foo')).code), + Method( + (b) => + b + ..name = 'returnsCastedValue' + ..returns = refer('Foo') + ..body = refer('bar').asA(refer('Foo')).code, + ), equalsDart(r''' Foo returnsCastedValue() => (bar as Foo) '''), @@ -81,9 +96,12 @@ void main() { test('should create a normal method implicitly', () { expect( - Method.returnsVoid((b) => b - ..name = 'assignTrue' - ..body = refer('topLevelFoo').assign(literalTrue).statement), + Method.returnsVoid( + (b) => + b + ..name = 'assignTrue' + ..body = refer('topLevelFoo').assign(literalTrue).statement, + ), equalsDart(r''' void assignTrue() { topLevelFoo = true; @@ -94,10 +112,13 @@ void main() { test('should create a getter', () { expect( - Method((b) => b - ..name = 'foo' - ..external = true - ..type = MethodType.getter), + Method( + (b) => + b + ..name = 'foo' + ..external = true + ..type = MethodType.getter, + ), equalsDart(r''' external get foo; '''), @@ -106,11 +127,14 @@ void main() { test('should create a setter', () { expect( - Method((b) => b - ..name = 'foo' - ..external = true - ..requiredParameters.add(Parameter((b) => b..name = 'foo')) - ..type = MethodType.setter), + Method( + (b) => + b + ..name = 'foo' + ..external = true + ..requiredParameters.add(Parameter((b) => b..name = 'foo')) + ..type = MethodType.setter, + ), equalsDart(r''' external set foo(foo); '''), @@ -119,9 +143,12 @@ void main() { test('should create a method with a return type', () { expect( - Method((b) => b - ..name = 'foo' - ..returns = refer('String')), + Method( + (b) => + b + ..name = 'foo' + ..returns = refer('String'), + ), equalsDart(r''' String foo(); '''), @@ -139,39 +166,50 @@ void main() { test('should create a method with a function type return type', () { expect( - Method((b) => b - ..name = 'foo' - ..returns = FunctionType((b) => b - ..returnType = refer('String') - ..requiredParameters.addAll([ - refer('int'), - ]))), + Method( + (b) => + b + ..name = 'foo' + ..returns = FunctionType( + (b) => + b + ..returnType = refer('String') + ..requiredParameters.addAll([refer('int')]), + ), + ), equalsDart(r''' String Function(int) foo(); '''), ); }); - test('should create a function type with an optional positional parameter', - () { - expect( - FunctionType((b) => b - ..returnType = refer('String') - ..optionalParameters.add(refer('int'))), - equalsDart(r''' + test( + 'should create a function type with an optional positional parameter', + () { + expect( + FunctionType( + (b) => + b + ..returnType = refer('String') + ..optionalParameters.add(refer('int')), + ), + equalsDart(r''' String Function([int]) '''), - ); - }); + ); + }, + ); - test( - 'should create a function type with a required ' + test('should create a function type with a required ' 'and an optional positional parameter', () { expect( - FunctionType((b) => b - ..returnType = refer('String') - ..requiredParameters.add(refer('int')) - ..optionalParameters.add(refer('int'))), + FunctionType( + (b) => + b + ..returnType = refer('String') + ..requiredParameters.add(refer('int')) + ..optionalParameters.add(refer('int')), + ), equalsDart(r''' String Function(int, [int, ]) '''), @@ -189,23 +227,28 @@ void main() { test('should create a function type with an optional named parameter', () { expect( - FunctionType((b) => b - ..returnType = refer('String') - ..namedParameters['named'] = refer('int')), + FunctionType( + (b) => + b + ..returnType = refer('String') + ..namedParameters['named'] = refer('int'), + ), equalsDart(r''' String Function({int named}) '''), ); }); - test( - 'should create a function type with a required ' + test('should create a function type with a required ' 'and an optional named parameter', () { expect( - FunctionType((b) => b - ..returnType = refer('String') - ..requiredParameters.add(refer('int')) - ..namedParameters['named'] = refer('int')), + FunctionType( + (b) => + b + ..returnType = refer('String') + ..requiredParameters.add(refer('int')) + ..namedParameters['named'] = refer('int'), + ), equalsDart(r''' String Function(int, {int named, }) '''), @@ -214,23 +257,28 @@ void main() { test('should create a function type with a required named parameter', () { expect( - FunctionType((b) => b - ..returnType = refer('String') - ..namedRequiredParameters['named'] = refer('int')), + FunctionType( + (b) => + b + ..returnType = refer('String') + ..namedRequiredParameters['named'] = refer('int'), + ), equalsDart(r''' String Function({required int named}) '''), ); }); - test( - 'should create a function type with a required named and an optional ' + test('should create a function type with a required named and an optional ' 'named parameter', () { expect( - FunctionType((b) => b - ..returnType = refer('String') - ..namedRequiredParameters['named'] = refer('int') - ..namedParameters['optional'] = refer('int')), + FunctionType( + (b) => + b + ..returnType = refer('String') + ..namedRequiredParameters['named'] = refer('int') + ..namedParameters['optional'] = refer('int'), + ), equalsDart(r''' String Function({required int named, int optional, }) '''), @@ -239,9 +287,12 @@ void main() { test('should create a typedef to a reference', () { expect( - TypeDef((b) => b - ..name = 'i32' - ..definition = const Reference('int')), + TypeDef( + (b) => + b + ..name = 'i32' + ..definition = const Reference('int'), + ), equalsDart(r''' typedef i32 = int; '''), @@ -250,11 +301,17 @@ void main() { test('should create a typedef to a function type', () { expect( - TypeDef((b) => b - ..name = 'MyMapper' - ..definition = FunctionType((b) => b - ..returnType = refer('String') - ..optionalParameters.add(refer('int')))), + TypeDef( + (b) => + b + ..name = 'MyMapper' + ..definition = FunctionType( + (b) => + b + ..returnType = refer('String') + ..optionalParameters.add(refer('int')), + ), + ), equalsDart(r''' typedef MyMapper = String Function([int]); '''), @@ -263,15 +320,22 @@ void main() { test('should create a method with a nested function type return type', () { expect( - Method((b) => b - ..name = 'foo' - ..returns = FunctionType((b) => b - ..returnType = FunctionType((b) => b - ..returnType = refer('String') - ..requiredParameters.add(refer('String'))) - ..requiredParameters.addAll([ - refer('int'), - ]))), + Method( + (b) => + b + ..name = 'foo' + ..returns = FunctionType( + (b) => + b + ..returnType = FunctionType( + (b) => + b + ..returnType = refer('String') + ..requiredParameters.add(refer('String')), + ) + ..requiredParameters.addAll([refer('int')]), + ), + ), equalsDart(r''' String Function(String) Function(int) foo(); '''), @@ -280,39 +344,71 @@ void main() { test('should create a method with a function type argument', () { expect( - Method((b) => b - ..name = 'foo' - ..requiredParameters.add(Parameter((b) => b - ..type = FunctionType((b) => b - ..returnType = refer('String') - ..requiredParameters.add(refer('int'))) - ..name = 'argument'))), - equalsDart(r''' + Method( + (b) => + b + ..name = 'foo' + ..requiredParameters.add( + Parameter( + (b) => + b + ..type = FunctionType( + (b) => + b + ..returnType = refer('String') + ..requiredParameters.add(refer('int')), + ) + ..name = 'argument', + ), + ), + ), + equalsDart(r''' foo(String Function(int) argument); - ''')); + '''), + ); }); test('should create a method with a nested function type argument', () { expect( - Method((b) => b - ..name = 'foo' - ..requiredParameters.add(Parameter((b) => b - ..type = FunctionType((b) => b - ..returnType = FunctionType((b) => b - ..returnType = refer('String') - ..requiredParameters.add(refer('String'))) - ..requiredParameters.add(refer('int'))) - ..name = 'argument'))), - equalsDart(r''' + Method( + (b) => + b + ..name = 'foo' + ..requiredParameters.add( + Parameter( + (b) => + b + ..type = FunctionType( + (b) => + b + ..returnType = FunctionType( + (b) => + b + ..returnType = refer('String') + ..requiredParameters.add( + refer('String'), + ), + ) + ..requiredParameters.add(refer('int')), + ) + ..name = 'argument', + ), + ), + ), + equalsDart(r''' foo(String Function(String) Function(int) argument); - ''')); + '''), + ); }); test('should create a method with generic types', () { expect( - Method((b) => b - ..name = 'foo' - ..types.add(refer('T'))), + Method( + (b) => + b + ..name = 'foo' + ..types.add(refer('T')), + ), equalsDart(r''' foo(); '''), @@ -321,9 +417,12 @@ void main() { test('should create an external method', () { expect( - Method((b) => b - ..name = 'foo' - ..external = true), + Method( + (b) => + b + ..name = 'foo' + ..external = true, + ), equalsDart(r''' external foo(); '''), @@ -332,9 +431,12 @@ void main() { test('should create a method with a body', () { expect( - Method((b) => b - ..name = 'foo' - ..body = const Code('return 1+ 2;')), + Method( + (b) => + b + ..name = 'foo' + ..body = const Code('return 1+ 2;'), + ), equalsDart(r''' foo() { return 1 + 2; @@ -345,10 +447,13 @@ void main() { test('should create a lambda method (explicitly)', () { expect( - Method((b) => b - ..name = 'foo' - ..lambda = true - ..body = const Code('1 + 2')), + Method( + (b) => + b + ..name = 'foo' + ..lambda = true + ..body = const Code('1 + 2'), + ), equalsDart(r''' foo() => 1 + 2 '''), @@ -358,11 +463,12 @@ void main() { test('should create a method with a body with references', () { final $LinkedHashMap = refer('LinkedHashMap', 'dart:collection'); expect( - Method((b) => b - ..name = 'foo' - ..body = Code.scope( - (a) => 'return ${a($LinkedHashMap)}();', - )), + Method( + (b) => + b + ..name = 'foo' + ..body = Code.scope((a) => 'return ${a($LinkedHashMap)}();'), + ), equalsDart(r''' foo() { return LinkedHashMap(); @@ -374,11 +480,10 @@ void main() { test('should create a method with a parameter', () { expect( Method( - (b) => b - ..name = 'fib' - ..requiredParameters.add( - Parameter((b) => b.name = 'i'), - ), + (b) => + b + ..name = 'fib' + ..requiredParameters.add(Parameter((b) => b.name = 'i')), ), equalsDart(r''' fib(i); @@ -389,13 +494,17 @@ void main() { test('should create a method with an annotated parameter', () { expect( Method( - (b) => b - ..name = 'fib' - ..requiredParameters.add( - Parameter((b) => b - ..name = 'i' - ..annotations.add(refer('deprecated'))), - ), + (b) => + b + ..name = 'fib' + ..requiredParameters.add( + Parameter( + (b) => + b + ..name = 'i' + ..annotations.add(refer('deprecated')), + ), + ), ), equalsDart(r''' fib(@deprecated i); @@ -406,15 +515,17 @@ void main() { test('should create a method with a parameter with a type', () { expect( Method( - (b) => b - ..name = 'fib' - ..requiredParameters.add( - Parameter( - (b) => b - ..name = 'i' - ..type = refer('int').type, - ), - ), + (b) => + b + ..name = 'fib' + ..requiredParameters.add( + Parameter( + (b) => + b + ..name = 'i' + ..type = refer('int').type, + ), + ), ), equalsDart(r''' fib(int i); @@ -425,16 +536,18 @@ void main() { test('should create a method with a covariant parameter with a type', () { expect( Method( - (b) => b - ..name = 'fib' - ..requiredParameters.add( - Parameter( - (b) => b - ..name = 'i' - ..covariant = true - ..type = refer('int').type, - ), - ), + (b) => + b + ..name = 'fib' + ..requiredParameters.add( + Parameter( + (b) => + b + ..name = 'i' + ..covariant = true + ..type = refer('int').type, + ), + ), ), equalsDart(r''' fib(covariant int i); @@ -445,23 +558,36 @@ void main() { test('should create a method with a parameter with a generic type', () { expect( Method( - (b) => b - ..name = 'foo' - ..types.add(TypeReference((b) => b - ..symbol = 'T' - ..bound = refer('Iterable'))) - ..requiredParameters.addAll([ - Parameter( - (b) => b - ..name = 't' - ..type = refer('T'), - ), - Parameter((b) => b - ..name = 'x' - ..type = TypeReference((b) => b - ..symbol = 'X' - ..types.add(refer('T')))), - ]), + (b) => + b + ..name = 'foo' + ..types.add( + TypeReference( + (b) => + b + ..symbol = 'T' + ..bound = refer('Iterable'), + ), + ) + ..requiredParameters.addAll([ + Parameter( + (b) => + b + ..name = 't' + ..type = refer('T'), + ), + Parameter( + (b) => + b + ..name = 'x' + ..type = TypeReference( + (b) => + b + ..symbol = 'X' + ..types.add(refer('T')), + ), + ), + ]), ), equalsDart(r''' foo(T t, X x, ); @@ -472,11 +598,10 @@ void main() { test('should create a method with an optional parameter', () { expect( Method( - (b) => b - ..name = 'fib' - ..optionalParameters.add( - Parameter((b) => b.name = 'i'), - ), + (b) => + b + ..name = 'fib' + ..optionalParameters.add(Parameter((b) => b.name = 'i')), ), equalsDart(r''' fib([i]); @@ -487,12 +612,13 @@ void main() { test('should create a method with multiple optional parameters', () { expect( Method( - (b) => b - ..name = 'foo' - ..optionalParameters.addAll([ - Parameter((b) => b.name = 'a'), - Parameter((b) => b.name = 'b'), - ]), + (b) => + b + ..name = 'foo' + ..optionalParameters.addAll([ + Parameter((b) => b.name = 'a'), + Parameter((b) => b.name = 'b'), + ]), ), equalsDart(r''' foo([a, b, ]); @@ -503,13 +629,17 @@ void main() { test('should create a method with an optional parameter with a value', () { expect( Method( - (b) => b - ..name = 'fib' - ..optionalParameters.add( - Parameter((b) => b - ..name = 'i' - ..defaultTo = const Code('0')), - ), + (b) => + b + ..name = 'fib' + ..optionalParameters.add( + Parameter( + (b) => + b + ..name = 'i' + ..defaultTo = const Code('0'), + ), + ), ), equalsDart(r''' fib([i = 0]); @@ -520,17 +650,19 @@ void main() { test('should create a method with a named required parameter', () { expect( Method( - (b) => b - ..name = 'fib' - ..optionalParameters.add( - Parameter( - (b) => b - ..name = 'i' - ..named = true - ..required = true - ..type = refer('int').type, - ), - ), + (b) => + b + ..name = 'fib' + ..optionalParameters.add( + Parameter( + (b) => + b + ..name = 'i' + ..named = true + ..required = true + ..type = refer('int').type, + ), + ), ), equalsDart(r''' fib({required int i}); @@ -541,18 +673,20 @@ void main() { test('should create a method with a named required covariant parameter', () { expect( Method( - (b) => b - ..name = 'fib' - ..optionalParameters.add( - Parameter( - (b) => b - ..name = 'i' - ..named = true - ..required = true - ..covariant = true - ..type = refer('int').type, - ), - ), + (b) => + b + ..name = 'fib' + ..optionalParameters.add( + Parameter( + (b) => + b + ..name = 'i' + ..named = true + ..required = true + ..covariant = true + ..type = refer('int').type, + ), + ), ), equalsDart(r''' fib({required covariant int i}); @@ -563,13 +697,17 @@ void main() { test('should create a method with a named optional parameter', () { expect( Method( - (b) => b - ..name = 'fib' - ..optionalParameters.add( - Parameter((b) => b - ..named = true - ..name = 'i'), - ), + (b) => + b + ..name = 'fib' + ..optionalParameters.add( + Parameter( + (b) => + b + ..named = true + ..name = 'i', + ), + ), ), equalsDart(r''' fib({i}); @@ -580,14 +718,18 @@ void main() { test('should create a method with a named optional parameter with value', () { expect( Method( - (b) => b - ..name = 'fib' - ..optionalParameters.add( - Parameter((b) => b - ..named = true - ..name = 'i' - ..defaultTo = const Code('0')), - ), + (b) => + b + ..name = 'fib' + ..optionalParameters.add( + Parameter( + (b) => + b + ..named = true + ..name = 'i' + ..defaultTo = const Code('0'), + ), + ), ), equalsDart(r''' fib({i = 0}); @@ -598,16 +740,18 @@ void main() { test('should create a method with a mix of parameters', () { expect( Method( - (b) => b - ..name = 'foo' - ..requiredParameters.add( - Parameter((b) => b..name = 'a'), - ) - ..optionalParameters.add( - Parameter((b) => b - ..named = true - ..name = 'b'), - ), + (b) => + b + ..name = 'foo' + ..requiredParameters.add(Parameter((b) => b..name = 'a')) + ..optionalParameters.add( + Parameter( + (b) => + b + ..named = true + ..name = 'b', + ), + ), ), equalsDart(r''' foo(a, {b, }); @@ -618,11 +762,10 @@ void main() { test('should create a method as a closure', () { expect( Method( - (b) => b - ..requiredParameters.add( - Parameter((b) => b..name = 'a'), - ) - ..body = const Code(''), + (b) => + b + ..requiredParameters.add(Parameter((b) => b..name = 'a')) + ..body = const Code(''), ).closure, equalsDart(r''' (a) { } diff --git a/pkgs/code_builder/test/specs/mixin_test.dart b/pkgs/code_builder/test/specs/mixin_test.dart index e167d02a5..97e9529d1 100644 --- a/pkgs/code_builder/test/specs/mixin_test.dart +++ b/pkgs/code_builder/test/specs/mixin_test.dart @@ -21,9 +21,12 @@ void main() { test('should create a base mixin', () { expect( - Mixin((b) => b - ..name = 'Foo' - ..base = true), + Mixin( + (b) => + b + ..name = 'Foo' + ..base = true, + ), equalsDart(r''' base mixin Foo {} '''), @@ -33,13 +36,10 @@ void main() { test('should create a mixin with documentations', () { expect( Mixin( - (b) => b - ..name = 'Foo' - ..docs.addAll( - const [ - '/// My favorite mixin.', - ], - ), + (b) => + b + ..name = 'Foo' + ..docs.addAll(const ['/// My favorite mixin.']), ), equalsDart(r''' /// My favorite mixin. @@ -51,12 +51,15 @@ void main() { test('should create a mixin with annotations', () { expect( Mixin( - (b) => b - ..name = 'Foo' - ..annotations.addAll([ - refer('deprecated'), - refer('Deprecated').call([literalString('This is an old mixin')]) - ]), + (b) => + b + ..name = 'Foo' + ..annotations.addAll([ + refer('deprecated'), + refer( + 'Deprecated', + ).call([literalString('This is an old mixin')]), + ]), ), equalsDart(r''' @deprecated @@ -68,9 +71,12 @@ void main() { test('should create a mixin with a generic type', () { expect( - Mixin((b) => b - ..name = 'List' - ..types.add(refer('T'))), + Mixin( + (b) => + b + ..name = 'List' + ..types.add(refer('T')), + ), equalsDart(r''' mixin List {} '''), @@ -80,12 +86,10 @@ void main() { test('should create a mixin with multiple generic types', () { expect( Mixin( - (b) => b - ..name = 'Map' - ..types.addAll([ - refer('K'), - refer('V'), - ]), + (b) => + b + ..name = 'Map' + ..types.addAll([refer('K'), refer('V')]), ), equalsDart(r''' mixin Map {} @@ -95,13 +99,24 @@ void main() { test('should create a mixin with a bound generic type', () { expect( - Mixin((b) => b - ..name = 'Comparable' - ..types.add(TypeReference((b) => b - ..symbol = 'T' - ..bound = TypeReference((b) => b - ..symbol = 'Comparable' - ..types.add(refer('T').type))))), + Mixin( + (b) => + b + ..name = 'Comparable' + ..types.add( + TypeReference( + (b) => + b + ..symbol = 'T' + ..bound = TypeReference( + (b) => + b + ..symbol = 'Comparable' + ..types.add(refer('T').type), + ), + ), + ), + ), equalsDart(r''' mixin Comparable> {} '''), @@ -110,9 +125,12 @@ void main() { test('should create a mixin on another mixin', () { expect( - Mixin((b) => b - ..name = 'Foo' - ..on = TypeReference((b) => b.symbol = 'Bar')), + Mixin( + (b) => + b + ..name = 'Foo' + ..on = TypeReference((b) => b.symbol = 'Bar'), + ), equalsDart(r''' mixin Foo on Bar {} '''), @@ -121,10 +139,13 @@ void main() { test('should create a mixin implementing another mixin', () { expect( - Mixin((b) => b - ..name = 'Foo' - ..on = TypeReference((b) => b.symbol = 'Bar') - ..implements.add(TypeReference((b) => b.symbol = 'Foo'))), + Mixin( + (b) => + b + ..name = 'Foo' + ..on = TypeReference((b) => b.symbol = 'Bar') + ..implements.add(TypeReference((b) => b.symbol = 'Foo')), + ), equalsDart(r''' mixin Foo on Bar implements Foo {} '''), @@ -133,11 +154,19 @@ void main() { test('should create a mixin with a method', () { expect( - Mixin((b) => b - ..name = 'Foo' - ..methods.add(Method((b) => b - ..name = 'foo' - ..body = const Code('return 1+ 2;')))), + Mixin( + (b) => + b + ..name = 'Foo' + ..methods.add( + Method( + (b) => + b + ..name = 'foo' + ..body = const Code('return 1+ 2;'), + ), + ), + ), equalsDart(r''' mixin Foo { foo() { diff --git a/pkgs/code_builder/test/specs/record_type_test.dart b/pkgs/code_builder/test/specs/record_type_test.dart index 0084c507d..55f5318ed 100644 --- a/pkgs/code_builder/test/specs/record_type_test.dart +++ b/pkgs/code_builder/test/specs/record_type_test.dart @@ -15,9 +15,12 @@ void main() { setUp(() => emitter = DartEmitter.scoped(useNullSafetySyntax: true)); final intRef = TypeReference((b) => b.symbol = 'int'); - TypeReference listRef(TypeReference argType) => TypeReference((b) => b - ..symbol = 'List' - ..types.add(argType)); + TypeReference listRef(TypeReference argType) => TypeReference( + (b) => + b + ..symbol = 'List' + ..types.add(argType), + ); test('should create an empty record type', () { expect(RecordType(), equalsDart('()', emitter)); @@ -25,44 +28,71 @@ void main() { test('should create a record type with positional fields', () { expect( - RecordType((b) => b - ..positionalFieldTypes.addAll( - [intRef, listRef(intRef).rebuild((b) => b..isNullable = true)]) - ..isNullable = true), + RecordType( + (b) => + b + ..positionalFieldTypes.addAll([ + intRef, + listRef(intRef).rebuild((b) => b..isNullable = true), + ]) + ..isNullable = true, + ), equalsDart('(int, List?)?', emitter), ); }); test('should create a record type with one positional field', () { - expect(RecordType((b) => b..positionalFieldTypes.add(intRef)), - equalsDart('(int,)', emitter)); + expect( + RecordType((b) => b..positionalFieldTypes.add(intRef)), + equalsDart('(int,)', emitter), + ); }); test('should create a record type with named fields', () { expect( - RecordType((b) => b - ..namedFieldTypes.addAll({ - 'named': intRef, - 'other': listRef(intRef), - })), - equalsDart('({int named, List other})', emitter)); + RecordType( + (b) => + b + ..namedFieldTypes.addAll({ + 'named': intRef, + 'other': listRef(intRef), + }), + ), + equalsDart('({int named, List other})', emitter), + ); }); test('should create a record type with both positional and named fields', () { expect( - RecordType((b) => b - ..positionalFieldTypes.add(listRef(intRef)) - ..namedFieldTypes.addAll({'named': intRef}) - ..isNullable = true), - equalsDart('(List, {int named})?', emitter)); + RecordType( + (b) => + b + ..positionalFieldTypes.add(listRef(intRef)) + ..namedFieldTypes.addAll({'named': intRef}) + ..isNullable = true, + ), + equalsDart('(List, {int named})?', emitter), + ); }); test('should create a nested record type', () { expect( - RecordType((b) => b - ..positionalFieldTypes.add(RecordType((b) => b - ..namedFieldTypes.addAll({'named': intRef, 'other': intRef}) - ..isNullable = true))), - equalsDart('(({int named, int other})?,)', emitter)); + RecordType( + (b) => + b + ..positionalFieldTypes.add( + RecordType( + (b) => + b + ..namedFieldTypes.addAll({ + 'named': intRef, + 'other': intRef, + }) + ..isNullable = true, + ), + ), + ), + equalsDart('(({int named, int other})?,)', emitter), + ); }); } diff --git a/pkgs/code_builder/test/specs/type_reference_test.dart b/pkgs/code_builder/test/specs/type_reference_test.dart index 35365cbf9..9291cad85 100644 --- a/pkgs/code_builder/test/specs/type_reference_test.dart +++ b/pkgs/code_builder/test/specs/type_reference_test.dart @@ -12,9 +12,12 @@ void main() { test('should create a nullable type in a pre-Null Safety library', () { expect( - TypeReference((b) => b - ..symbol = 'Foo' - ..isNullable = true), + TypeReference( + (b) => + b + ..symbol = 'Foo' + ..isNullable = true, + ), equalsDart(r''' Foo '''), @@ -28,9 +31,12 @@ void main() { test('should create a nullable type', () { expect( - TypeReference((b) => b - ..symbol = 'Foo' - ..isNullable = true), + TypeReference( + (b) => + b + ..symbol = 'Foo' + ..isNullable = true, + ), equalsDart(r'Foo?', emitter), ); }); @@ -44,11 +50,19 @@ void main() { test('should create a type with nullable type arguments', () { expect( - TypeReference((b) => b - ..symbol = 'List' - ..types.add(TypeReference((b) => b - ..symbol = 'int' - ..isNullable = true))), + TypeReference( + (b) => + b + ..symbol = 'List' + ..types.add( + TypeReference( + (b) => + b + ..symbol = 'int' + ..isNullable = true, + ), + ), + ), equalsDart(r'List', emitter), ); });