From 0a39d7b0d588fe0f8e6945d88a2279f74786ea7b Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Thu, 9 Aug 2018 16:53:27 -0700 Subject: [PATCH] Run dartfmt --fix to drop optional new - Set minimum SDK to one that is Dart 2 by default. - Run dartfmt --fix - Test on stable on Travis. --- .travis.yml | 13 +++ analysis_options.yaml | 1 + source_gen/.mono_repo.yml | 1 + source_gen/lib/builder.dart | 16 +-- source_gen/lib/src/builder.dart | 22 ++-- source_gen/lib/src/constants/reader.dart | 21 ++-- source_gen/lib/src/constants/revive.dart | 12 +- source_gen/lib/src/constants/utils.dart | 2 +- source_gen/lib/src/generated_output.dart | 2 +- source_gen/lib/src/generator.dart | 2 +- .../lib/src/generator_for_annotation.dart | 4 +- source_gen/lib/src/library.dart | 19 ++-- source_gen/lib/src/output_helpers.dart | 6 +- source_gen/lib/src/span_for_element.dart | 8 +- source_gen/lib/src/type_checker.dart | 16 +-- source_gen/pubspec.yaml | 4 +- source_gen/test/builder_test.dart | 107 +++++++++--------- source_gen/test/constants_test.dart | 12 +- .../test/generator_for_annotation_test.dart | 14 +-- source_gen/test/library/find_type_test.dart | 2 +- source_gen/test/library/path_to_url_test.dart | 12 +- source_gen/test/output_helpers_test.dart | 30 +++-- source_gen/test/span_for_element_test.dart | 2 +- source_gen/test/src/comment_generator.dart | 2 +- .../test/test_files/annotated_classes.dart | 7 +- .../test_files/annotated_classes_part.dart | 4 +- source_gen/test/test_files/annotations.dart | 10 +- source_gen/test/type_checker_test.dart | 28 ++--- 28 files changed, 194 insertions(+), 185 deletions(-) diff --git a/.travis.yml b/.travis.yml index e832a9dc..cc608dd0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,17 +4,30 @@ language: dart jobs: include: - stage: analyze_format + name: "SDK: dev - DIR: _test_annotations - TASKS: [dartfmt -n --set-exit-if-changed ., dartanalyzer --fatal-infos --fatal-warnings .]" script: ./tool/travis.sh dartfmt dartanalyzer env: PKG="_test_annotations" dart: dev - stage: analyze_format + name: "SDK: dev - DIR: source_gen - TASKS: [dartfmt -n --set-exit-if-changed ., dartanalyzer --fatal-infos --fatal-warnings .]" script: ./tool/travis.sh dartfmt dartanalyzer env: PKG="source_gen" dart: dev + - stage: analyze_format + name: "SDK: stable - DIR: source_gen - TASKS: [dartfmt -n --set-exit-if-changed ., dartanalyzer --fatal-infos --fatal-warnings .]" + script: ./tool/travis.sh dartfmt dartanalyzer + env: PKG="source_gen" + dart: stable - stage: unit_test + name: "SDK: dev - DIR: source_gen - TASKS: pub run test -j 1" script: ./tool/travis.sh test env: PKG="source_gen" dart: dev + - stage: unit_test + name: "SDK: stable - DIR: source_gen - TASKS: pub run test -j 1" + script: ./tool/travis.sh test + env: PKG="source_gen" + dart: stable stages: - analyze_format diff --git a/analysis_options.yaml b/analysis_options.yaml index 5b8df658..05a01966 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -67,6 +67,7 @@ linter: - unnecessary_brace_in_string_interps - unnecessary_getters_setters - unnecessary_lambdas + - unnecessary_new - unnecessary_null_aware_assignments - unnecessary_statements - unnecessary_this diff --git a/source_gen/.mono_repo.yml b/source_gen/.mono_repo.yml index 21965eec..d62bf52e 100644 --- a/source_gen/.mono_repo.yml +++ b/source_gen/.mono_repo.yml @@ -1,6 +1,7 @@ # See https://github.com/dart-lang/mono_repo for details dart: - dev + - stable stages: - analyze_format: diff --git a/source_gen/lib/builder.dart b/source_gen/lib/builder.dart index 899abe8f..ad987f3f 100644 --- a/source_gen/lib/builder.dart +++ b/source_gen/lib/builder.dart @@ -24,14 +24,14 @@ const _outputExtensions = '.g.dart'; const _partFiles = '.g.part'; Builder combiningBuilder([BuilderOptions options]) { - var optionsMap = new Map.from(options?.config ?? {}); + var optionsMap = Map.from(options?.config ?? {}); - var builder = new CombiningBuilder( + var builder = CombiningBuilder( includePartName: optionsMap.remove('include_part_name') as bool); if (optionsMap.isNotEmpty) { if (log == null) { - throw new StateError('Upgrade `build_runner` to at least 0.8.2.'); + throw StateError('Upgrade `build_runner` to at least 0.8.2.'); } else { log.warning('These options were ignored: `$optionsMap`.'); } @@ -40,7 +40,7 @@ Builder combiningBuilder([BuilderOptions options]) { } PostProcessBuilder partCleanup(BuilderOptions options) => - const FileDeletingBuilder(const ['.g.part']); + const FileDeletingBuilder(['.g.part']); /// A [Builder] which combines part files generated from [SharedPartBuilder]. /// @@ -50,7 +50,7 @@ class CombiningBuilder implements Builder { @override Map> get buildExtensions => const { - '.dart': const [_outputExtensions] + '.dart': [_outputExtensions] }; /// Returns a new [CombiningBuilder]. @@ -71,7 +71,7 @@ class CombiningBuilder implements Builder { // Pattern used to ensure items are only considered if they match // [file name without extension].[valid part id].[part file extension] - var restrictedPattern = new RegExp([ + var restrictedPattern = RegExp([ '^', // start of string RegExp.escape(inputBaseName), // file name, without extension '\.', // `.` character @@ -81,12 +81,12 @@ class CombiningBuilder implements Builder { ].join('')); var assetIds = await buildStep - .findAssets(new Glob(pattern)) + .findAssets(Glob(pattern)) .where((id) => restrictedPattern.hasMatch(id.pathSegments.last)) .toList() ..sort(); - var assets = await new Stream.fromIterable(assetIds) + var assets = await Stream.fromIterable(assetIds) .asyncMap((id) async { var content = (await buildStep.readAsString(id)).trim(); if (_includePartName) { diff --git a/source_gen/lib/src/builder.dart b/source_gen/lib/src/builder.dart index 76c75a56..c8af25e5 100644 --- a/source_gen/lib/src/builder.dart +++ b/source_gen/lib/src/builder.dart @@ -46,14 +46,14 @@ class _Builder extends Builder { formatOutput = formatOutput ?? _formatter.format, _header = (header ?? defaultFileHeader).trim() { if (_generatedExtension == null) { - throw new ArgumentError.notNull('generatedExtension'); + throw ArgumentError.notNull('generatedExtension'); } if (_generatedExtension.isEmpty || !_generatedExtension.startsWith('.')) { - throw new ArgumentError.value(_generatedExtension, 'generatedExtension', + throw ArgumentError.value(_generatedExtension, 'generatedExtension', 'Extension must be in the format of .*'); } if (_isLibraryBuilder && _generators.length > 1) { - throw new ArgumentError( + throw ArgumentError( 'A standalone file can only be generated from a single Generator.'); } } @@ -79,7 +79,7 @@ class _Builder extends Builder { if (generatedOutputs.isEmpty) return; final outputId = buildStep.inputId.changeExtension(_generatedExtension); - var contentBuffer = new StringBuffer(); + var contentBuffer = StringBuffer(); if (_header.isNotEmpty) { contentBuffer.writeln(_header); @@ -90,7 +90,7 @@ class _Builder extends Builder { var name = nameOfPartial(library, asset); if (name == null) { var suggest = suggestLibraryName(asset); - throw new InvalidGenerationSourceError( + throw InvalidGenerationSourceError( 'Could not find library identifier so a "part of" cannot be built.', todo: '' 'Consider adding the following to your source file:\n\n' @@ -175,7 +175,7 @@ class SharedPartBuilder extends _Builder { additionalOutputExtensions: additionalOutputExtensions, header: '') { if (!_partIdRegExp.hasMatch(partId)) { - throw new ArgumentError.value( + throw ArgumentError.value( partId, 'partId', '`partId` can only contain letters, numbers, `_` and `.`. ' @@ -241,7 +241,7 @@ class LibraryBuilder extends _Builder { Stream _generate(LibraryElement library, List generators, BuildStep buildStep) async* { - var libraryReader = new LibraryReader(library); + var libraryReader = LibraryReader(library); for (var i = 0; i < generators.length; i++) { var gen = generators[i]; try { @@ -261,15 +261,15 @@ Stream _generate(LibraryElement library, continue; } - yield new GeneratedOutput(gen, createdUnit); + yield GeneratedOutput(gen, createdUnit); } catch (e, stack) { log.severe('Error running $gen', e, stack); - yield new GeneratedOutput.fromError(gen, e, stack); + yield GeneratedOutput.fromError(gen, e, stack); } } } -final _formatter = new DartFormatter(); +final _formatter = DartFormatter(); const defaultFileHeader = '// GENERATED CODE - DO NOT MODIFY BY HAND'; @@ -277,4 +277,4 @@ final _headerLine = '// '.padRight(77, '*'); const partIdRegExpLiteral = r'[A-Za-z_\d-]+'; -final _partIdRegExp = new RegExp('^$partIdRegExpLiteral\$'); +final _partIdRegExp = RegExp('^$partIdRegExpLiteral\$'); diff --git a/source_gen/lib/src/constants/reader.dart b/source_gen/lib/src/constants/reader.dart index 364bf1ae..494ae571 100644 --- a/source_gen/lib/src/constants/reader.dart +++ b/source_gen/lib/src/constants/reader.dart @@ -16,9 +16,8 @@ import 'utils.dart'; /// Unlike [DartObject.getField], the [read] method attempts to access super /// classes for the field value if not found. abstract class ConstantReader { - factory ConstantReader(DartObject object) => isNullLike(object) - ? const _NullConstant() - : new _DartObjectConstant(object); + factory ConstantReader(DartObject object) => + isNullLike(object) ? const _NullConstant() : _DartObjectConstant(object); const ConstantReader._(); @@ -124,13 +123,13 @@ abstract class ConstantReader { class _NullConstant extends ConstantReader { @alwaysThrows static T _throw(String expected) { - throw new FormatException('Not an instance of $expected.'); + throw FormatException('Not an instance of $expected.'); } const _NullConstant() : super._(); @override - DartObject get objectValue => throw new UnsupportedError('Null'); + DartObject get objectValue => throw UnsupportedError('Null'); @override bool get boolValue => _throw('bool'); @@ -151,7 +150,7 @@ class _NullConstant extends ConstantReader { ConstantReader peek(_) => null; @override - ConstantReader read(_) => throw new UnsupportedError('Null'); + ConstantReader read(_) => throw UnsupportedError('Null'); @override String get stringValue => _throw('String'); @@ -163,7 +162,7 @@ class _NullConstant extends ConstantReader { DartType get typeValue => _throw('Type'); @override - Revivable revive() => throw new UnsupportedError('Null'); + Revivable revive() => throw UnsupportedError('Null'); } class _DartObjectConstant extends ConstantReader { @@ -174,7 +173,7 @@ class _DartObjectConstant extends ConstantReader { T _check(T value, String expected) { if (value == null) { - throw new FormatException('Not an instance of $expected.', objectValue); + throw FormatException('Not an instance of $expected.', objectValue); } return value; } @@ -187,7 +186,7 @@ class _DartObjectConstant extends ConstantReader { objectValue.toDoubleValue() ?? objectValue.toListValue() ?? objectValue.toMapValue() ?? - new Symbol(_check(objectValue.toSymbolValue(), 'literal')); + Symbol(_check(objectValue.toSymbolValue(), 'literal')); @override bool get isLiteral => @@ -249,7 +248,7 @@ class _DartObjectConstant extends ConstantReader { @override Symbol get symbolValue => - new Symbol(_check(objectValue.toSymbolValue(), 'Symbol')); + Symbol(_check(objectValue.toSymbolValue(), 'Symbol')); @override bool get isType => objectValue.toTypeValue() != null; @@ -259,7 +258,7 @@ class _DartObjectConstant extends ConstantReader { @override ConstantReader peek(String field) { - final constant = new ConstantReader(getFieldRecursive(objectValue, field)); + final constant = ConstantReader(getFieldRecursive(objectValue, field)); return constant.isNull ? null : constant; } diff --git a/source_gen/lib/src/constants/revive.dart b/source_gen/lib/src/constants/revive.dart index f22f588d..c8cff0ae 100644 --- a/source_gen/lib/src/constants/revive.dart +++ b/source_gen/lib/src/constants/revive.dart @@ -23,13 +23,13 @@ Revivable reviveInstance(DartObject object, [LibraryElement origin]) { final element = object.type.element; var url = Uri.parse(urlOfElement(element)); if (element is FunctionElement) { - return new Revivable._( + return Revivable._( source: url.removeFragment(), accessor: element.name, ); } if (element is MethodElement && element.isStatic) { - return new Revivable._( + return Revivable._( source: url.removeFragment(), accessor: '${element.enclosingElement.name}.${element.name}', ); @@ -39,7 +39,7 @@ Revivable reviveInstance(DartObject object, [LibraryElement origin]) { if (clazz.isEnum) { for (final e in clazz.fields.where( (f) => f.isPublic && f.isConst && f.computeConstantValue() == object)) { - return new Revivable._( + return Revivable._( source: url.removeFragment(), accessor: '${clazz.name}.${e.name}', ); @@ -49,7 +49,7 @@ Revivable reviveInstance(DartObject object, [LibraryElement origin]) { .expand((t) => t.fields) .where((f) => f.isPublic && f.isConst && f.computeConstantValue() == object)) { - return new Revivable._( + return Revivable._( source: url.removeFragment(), accessor: '${clazz.name}.${e.name}', ); @@ -59,7 +59,7 @@ Revivable reviveInstance(DartObject object, [LibraryElement origin]) { i.constructor.isPublic && i.constructor.enclosingElement.isPublic) { url = Uri.parse(urlOfElement(i.constructor.enclosingElement)); - return new Revivable._( + return Revivable._( source: url, accessor: i.constructor.name, namedArguments: i.namedArguments, @@ -72,7 +72,7 @@ Revivable reviveInstance(DartObject object, [LibraryElement origin]) { for (final e in origin.definingCompilationUnit.topLevelVariables.where( (f) => f.isPublic && f.isConst && f.computeConstantValue() == object, )) { - return new Revivable._( + return Revivable._( source: Uri.parse(urlOfElement(origin)).replace(fragment: ''), accessor: e.name, ); diff --git a/source_gen/lib/src/constants/utils.dart b/source_gen/lib/src/constants/utils.dart index 58872638..989ae0c7 100644 --- a/source_gen/lib/src/constants/utils.dart +++ b/source_gen/lib/src/constants/utils.dart @@ -19,7 +19,7 @@ void assertHasField(ClassElement root, String name) { } final allFields = root.fields.toSet() ..addAll(root.allSupertypes.expand((t) => t.element.fields)); - throw new FormatException( + throw FormatException( 'Class ${root.name} does not have field "$name".', 'Fields: \n - ${allFields.map((e) => e.name).join('\n - ')}', ); diff --git a/source_gen/lib/src/generated_output.dart b/source_gen/lib/src/generated_output.dart index 390ff42f..5ce26807 100644 --- a/source_gen/lib/src/generated_output.dart +++ b/source_gen/lib/src/generated_output.dart @@ -36,7 +36,7 @@ class GeneratedOutput { } String _outputFromError(Object error) { - var buffer = new StringBuffer(); + var buffer = StringBuffer(); _commentWithHeader(_errorHeader, error.toString(), buffer); diff --git a/source_gen/lib/src/generator.dart b/source_gen/lib/src/generator.dart index fc89c94b..8c2ad368 100644 --- a/source_gen/lib/src/generator.dart +++ b/source_gen/lib/src/generator.dart @@ -48,7 +48,7 @@ class InvalidGenerationSourceError extends Error { @override String toString() { - var buffer = new StringBuffer(message); + var buffer = StringBuffer(message); if (element != null) { var span = spanForElement(element); diff --git a/source_gen/lib/src/generator_for_annotation.dart b/source_gen/lib/src/generator_for_annotation.dart index 6f358d60..9f54b4ac 100644 --- a/source_gen/lib/src/generator_for_annotation.dart +++ b/source_gen/lib/src/generator_for_annotation.dart @@ -37,11 +37,11 @@ import 'type_checker.dart'; abstract class GeneratorForAnnotation extends Generator { const GeneratorForAnnotation(); - TypeChecker get typeChecker => new TypeChecker.fromRuntime(T); + TypeChecker get typeChecker => TypeChecker.fromRuntime(T); @override FutureOr generate(LibraryReader library, BuildStep buildStep) async { - var values = new Set(); + var values = Set(); for (var annotatedElement in library.annotatedWith(typeChecker)) { var generatedValue = generateForAnnotatedElement( diff --git a/source_gen/lib/src/library.dart b/source_gen/lib/src/library.dart index 238f5b8a..46a531e1 100644 --- a/source_gen/lib/src/library.dart +++ b/source_gen/lib/src/library.dart @@ -31,7 +31,7 @@ class LibraryReader { LibraryReader(this.element); Namespace get _namespace => _namespaceCache ??= - new NamespaceBuilder().createExportNamespaceForLibrary(element); + NamespaceBuilder().createExportNamespaceForLibrary(element); /// Returns a top-level [ClassElement] publicly visible in by [name]. /// @@ -56,7 +56,7 @@ class LibraryReader { final annotation = checker.firstAnnotationOf(element, throwOnUnresolved: throwOnUnresolved); if (annotation != null) { - yield new AnnotatedElement(new ConstantReader(annotation), element); + yield AnnotatedElement(ConstantReader(annotation), element); } } } @@ -68,7 +68,7 @@ class LibraryReader { final annotation = checker.firstAnnotationOfExact(element, throwOnUnresolved: throwOnUnresolved); if (annotation != null) { - yield new AnnotatedElement(new ConstantReader(annotation), element); + yield AnnotatedElement(ConstantReader(annotation), element); } } } @@ -99,7 +99,7 @@ class LibraryReader { /// May throw [ArgumentError] if it is not possible to resolve a path. Uri pathToUrl(dynamic toUrlOrString) { if (toUrlOrString == null) { - throw new ArgumentError.notNull('toUrlOrString'); + throw ArgumentError.notNull('toUrlOrString'); } final to = toUrlOrString is Uri ? toUrlOrString @@ -123,7 +123,7 @@ class LibraryReader { } var from = element.source.uri; if (from == null) { - throw new StateError('Current library has no source URL'); + throw StateError('Current library has no source URL'); } // Normalize (convert to an asset: URL). from = normalizeUrl(from); @@ -131,7 +131,7 @@ class LibraryReader { if (from == to) { // Edge-case: p.relative('a.dart', 'a.dart') == '.', but that is not // a valid import URL in Dart source code. - return new Uri(path: to.pathSegments.last); + return Uri(path: to.pathSegments.last); } final relative = p.toUri(p.relative( to.toString(), @@ -142,9 +142,9 @@ class LibraryReader { pathSegments: relative.pathSegments.skip(1), ); } - throw new ArgumentError.value(to, 'to', 'Not relative to $from'); + throw ArgumentError.value(to, 'to', 'Not relative to $from'); } - throw new ArgumentError.value(to, 'to', 'Cannot use scheme "${to.scheme}"'); + throw ArgumentError.value(to, 'to', 'Cannot use scheme "${to.scheme}"'); } /// Returns whether both [from] and [to] are in the same package and folder. @@ -175,8 +175,7 @@ class LibraryReader { } var element = resolutionMap.elementDeclaredByDeclaration(member); if (element == null) { - throw new StateError( - 'Could not find any elements for the provided unit.'); + throw StateError('Could not find any elements for the provided unit.'); } return [element]; } diff --git a/source_gen/lib/src/output_helpers.dart b/source_gen/lib/src/output_helpers.dart index d0ce10ee..6aa57b57 100644 --- a/source_gen/lib/src/output_helpers.dart +++ b/source_gen/lib/src/output_helpers.dart @@ -11,7 +11,7 @@ import 'package:async/async.dart'; /// exceptions are forwarded through the return value. Stream normalizeGeneratorOutput(Object value) { if (value == null) { - return new Stream.empty(); + return Stream.empty(); } else if (value is Future) { return StreamCompleter.fromFuture(value.then(normalizeGeneratorOutput)); } else if (value is String) { @@ -19,7 +19,7 @@ Stream normalizeGeneratorOutput(Object value) { } if (value is Iterable) { - value = new Stream.fromIterable(value as Iterable); + value = Stream.fromIterable(value as Iterable); } if (value is Stream) { @@ -34,6 +34,6 @@ Stream normalizeGeneratorOutput(Object value) { throw _argError(value); } -ArgumentError _argError(Object value) => new ArgumentError( +ArgumentError _argError(Object value) => ArgumentError( 'Must be a String or be an Iterable/Stream containing String values. ' 'Found `${Error.safeToString(value)}` (${value.runtimeType}).'); diff --git a/source_gen/lib/src/span_for_element.dart b/source_gen/lib/src/span_for_element.dart index cbc57570..473b98b4 100644 --- a/source_gen/lib/src/span_for_element.dart +++ b/source_gen/lib/src/span_for_element.dart @@ -23,19 +23,19 @@ SourceSpan spanForElement(Element element, [SourceFile file]) { if (file == null) { final contents = element?.source?.contents; if (contents == null) { - return new SourceSpan( - new SourceLocation( + return SourceSpan( + SourceLocation( element.nameOffset, sourceUrl: url, ), - new SourceLocation( + SourceLocation( element.nameOffset + element.nameLength, sourceUrl: url, ), element.name, ); } - file = new SourceFile.fromString(contents.data, url: url); + file = SourceFile.fromString(contents.data, url: url); } return file.span(element.nameOffset, element.nameOffset + element.nameLength); } diff --git a/source_gen/lib/src/type_checker.dart b/source_gen/lib/src/type_checker.dart index 1dfa8748..f88d820a 100644 --- a/source_gen/lib/src/type_checker.dart +++ b/source_gen/lib/src/type_checker.dart @@ -106,7 +106,7 @@ abstract class TypeChecker { final annotation = element.metadata[annotationIndex]; final result = annotation.computeConstantValue(); if (result == null && throwOnUnresolved) { - throw new UnresolvedAnnotationException._from(element, annotationIndex); + throw UnresolvedAnnotationException._from(element, annotationIndex); } return result; } @@ -219,14 +219,14 @@ class _MirrorTypeChecker extends TypeChecker { .replace(fragment: MirrorSystem.getName(mirror.simpleName)); // Precomputed type checker for types that already have been used. - static final _cache = new Expando(); + static final _cache = Expando(); final Type _type; const _MirrorTypeChecker(this._type) : super._(); TypeChecker get _computed => - _cache[this] ??= new TypeChecker.fromUrl(_uriOf(reflectClass(_type))); + _cache[this] ??= TypeChecker.fromUrl(_uriOf(reflectClass(_type))); @override bool isExactly(Element element) => _computed.isExactly(element); @@ -240,7 +240,7 @@ class _UriTypeChecker extends TypeChecker { final String _url; // Precomputed cache of String --> Uri. - static final _cache = new Expando(); + static final _cache = Expando(); const _UriTypeChecker(dynamic url) : _url = '$url', @@ -303,9 +303,9 @@ class UnresolvedAnnotationException implements Exception { } final start = astNode.offset; final end = start + astNode.length; - return new SourceSpan( - new SourceLocation(start, sourceUrl: annotation.source.uri), - new SourceLocation(end, sourceUrl: annotation.source.uri), + return SourceSpan( + SourceLocation(start, sourceUrl: annotation.source.uri), + SourceLocation(end, sourceUrl: annotation.source.uri), contents.substring(start, end), ); } @@ -318,7 +318,7 @@ class UnresolvedAnnotationException implements Exception { ) { final annotation = annotatedElement.metadata[annotationIndex]; final sourceSpan = _getSourceSpanFrom(annotation); - return new UnresolvedAnnotationException._(annotatedElement, sourceSpan); + return UnresolvedAnnotationException._(annotatedElement, sourceSpan); } const UnresolvedAnnotationException._( diff --git a/source_gen/pubspec.yaml b/source_gen/pubspec.yaml index e79b9c17..d2302ef1 100644 --- a/source_gen/pubspec.yaml +++ b/source_gen/pubspec.yaml @@ -1,10 +1,10 @@ name: source_gen -version: 0.9.0+1 +version: 0.9.1-dev author: Dart Team description: Automated source code generation for Dart. homepage: https://github.com/dart-lang/source_gen environment: - sdk: '>=2.0.0-dev.19.0 <3.0.0' + sdk: '>=2.0.0-dev.64.0 <3.0.0' dependencies: analyzer: '>=0.31.0 <0.33.0' async: ^2.0.7 diff --git a/source_gen/test/builder_test.dart b/source_gen/test/builder_test.dart index f2d8d49a..29ac907f 100644 --- a/source_gen/test/builder_test.dart +++ b/source_gen/test/builder_test.dart @@ -21,10 +21,10 @@ void main() { test('Bad generated source', () async { var srcs = _createPackageStub(); - var builder = new PartBuilder([const _BadOutputGenerator()], '.foo.dart'); + var builder = PartBuilder([const _BadOutputGenerator()], '.foo.dart'); await testBuilder(builder, srcs, - generateFor: new Set.from(['$_pkgName|lib/test_lib.dart']), + generateFor: Set.from(['$_pkgName|lib/test_lib.dart']), outputs: { '$_pkgName|lib/test_lib.foo.dart': decodedMatches(contains('not valid code!')), @@ -33,9 +33,9 @@ void main() { test('Generate standalone output file', () async { var srcs = _createPackageStub(); - var builder = new LibraryBuilder(const CommentGenerator()); + var builder = LibraryBuilder(const CommentGenerator()); await testBuilder(builder, srcs, - generateFor: new Set.from(['$_pkgName|lib/test_lib.dart']), + generateFor: Set.from(['$_pkgName|lib/test_lib.dart']), outputs: { '$_pkgName|lib/test_lib.g.dart': _testGenStandaloneContent, }); @@ -44,9 +44,9 @@ void main() { test('Generate standalone output file with custom header', () async { var srcs = _createPackageStub(); var builder = - new LibraryBuilder(const CommentGenerator(), header: _customHeader); + LibraryBuilder(const CommentGenerator(), header: _customHeader); await testBuilder(builder, srcs, - generateFor: new Set.from(['$_pkgName|lib/test_lib.dart']), + generateFor: Set.from(['$_pkgName|lib/test_lib.dart']), outputs: { '$_pkgName|lib/test_lib.g.dart': decodedMatches(startsWith('$_customHeader\n\n// ***')) @@ -55,9 +55,9 @@ void main() { test('LibraryBuilder omits header if provided an empty String', () async { var srcs = _createPackageStub(); - var builder = new LibraryBuilder(const CommentGenerator(), header: ''); + var builder = LibraryBuilder(const CommentGenerator(), header: ''); await testBuilder(builder, srcs, - generateFor: new Set.from(['$_pkgName|lib/test_lib.dart']), + generateFor: Set.from(['$_pkgName|lib/test_lib.dart']), outputs: { '$_pkgName|lib/test_lib.g.dart': decodedMatches(startsWith('// ***')) }); @@ -66,14 +66,14 @@ void main() { test('Expect no error when multiple generators used on nonstandalone builder', () async { expect( - () => new PartBuilder( + () => PartBuilder( [const CommentGenerator(), const _LiteralGenerator()], '.foo.dart'), returnsNormally); }); test('Allow no "library" by default', () async { var sources = _createPackageStub(testLibContent: 'class A {}'); - var builder = new PartBuilder([const CommentGenerator()], '.foo.dart'); + var builder = PartBuilder([const CommentGenerator()], '.foo.dart'); await testBuilder(builder, sources, outputs: {'$_pkgName|lib/test_lib.foo.dart': _testGenNoLibrary}); @@ -81,14 +81,14 @@ void main() { test('Does not fail when there is no output', () async { var sources = _createPackageStub(testLibContent: 'class A {}'); - var builder = new PartBuilder( - [const CommentGenerator(forClasses: false)], '.foo.dart'); + var builder = + PartBuilder([const CommentGenerator(forClasses: false)], '.foo.dart'); await testBuilder(builder, sources, outputs: {}); }); test('Use new part syntax when no library directive exists', () async { var sources = _createPackageStub(testLibContent: 'class A {}'); - var builder = new PartBuilder([const CommentGenerator()], '.foo.dart'); + var builder = PartBuilder([const CommentGenerator()], '.foo.dart'); await testBuilder(builder, sources, outputs: {'$_pkgName|lib/test_lib.foo.dart': _testGenNoLibrary}); }); @@ -113,9 +113,9 @@ void main() { test('handle generator errors well', () async { var srcs = _createPackageStub(testLibContent: _testLibContentWithError); - var builder = new PartBuilder([const CommentGenerator()], '.foo.dart'); + var builder = PartBuilder([const CommentGenerator()], '.foo.dart'); await testBuilder(builder, srcs, - generateFor: new Set.from(['$_pkgName|lib/test_lib.dart']), + generateFor: Set.from(['$_pkgName|lib/test_lib.dart']), outputs: { '$_pkgName|lib/test_lib.foo.dart': _testGenPartContentError, }); @@ -123,7 +123,7 @@ void main() { test('warns when a non-standalone builder does not see "part"', () async { var srcs = _createPackageStub(testLibContent: _testLibContentNoPart); - var builder = new PartBuilder([const CommentGenerator()], '.foo.dart'); + var builder = PartBuilder([const CommentGenerator()], '.foo.dart'); var logs = []; await testBuilder( builder, @@ -170,9 +170,9 @@ void main() { test('defaults to formatting generated code with the DartFormatter', () async { await testBuilder( - new PartBuilder([const UnformattedCodeGenerator()], '.foo.dart'), + PartBuilder([const UnformattedCodeGenerator()], '.foo.dart'), {'$_pkgName|lib/a.dart': 'library a; part "a.part.dart";'}, - generateFor: new Set.from(['$_pkgName|lib/a.dart']), + generateFor: Set.from(['$_pkgName|lib/a.dart']), outputs: { '$_pkgName|lib/a.foo.dart': decodedMatches(contains(UnformattedCodeGenerator.formattedCode)), @@ -181,10 +181,10 @@ void main() { test('PartBuilder uses a custom header when provided', () async { await testBuilder( - new PartBuilder([const UnformattedCodeGenerator()], '.foo.dart', + PartBuilder([const UnformattedCodeGenerator()], '.foo.dart', header: _customHeader), {'$_pkgName|lib/a.dart': 'library a; part "a.part.dart";'}, - generateFor: new Set.from(['$_pkgName|lib/a.dart']), + generateFor: Set.from(['$_pkgName|lib/a.dart']), outputs: { '$_pkgName|lib/a.foo.dart': decodedMatches(startsWith('$_customHeader\n\npart of')), @@ -193,10 +193,10 @@ void main() { test('PartBuilder includes no header when `header` is empty', () async { await testBuilder( - new PartBuilder([const UnformattedCodeGenerator()], '.foo.dart', + PartBuilder([const UnformattedCodeGenerator()], '.foo.dart', header: ''), {'$_pkgName|lib/a.dart': 'library a; part "a.part.dart";'}, - generateFor: new Set.from(['$_pkgName|lib/a.dart']), + generateFor: Set.from(['$_pkgName|lib/a.dart']), outputs: { '$_pkgName|lib/a.foo.dart': decodedMatches(startsWith('part of')), }); @@ -205,8 +205,7 @@ void main() { group('SharedPartBuilder', () { test('warns about missing part', () async { var srcs = _createPackageStub(testLibContent: _testLibContentNoPart); - var builder = - new SharedPartBuilder([const CommentGenerator()], 'comment'); + var builder = SharedPartBuilder([const CommentGenerator()], 'comment'); var logs = []; await testBuilder( builder, @@ -220,12 +219,12 @@ void main() { test('outputs .g.part files', () async { await testBuilder( - new SharedPartBuilder( + SharedPartBuilder( [const UnformattedCodeGenerator()], 'foo', ), {'$_pkgName|lib/a.dart': 'library a; part "a.g.dart";'}, - generateFor: new Set.from(['$_pkgName|lib/a.dart']), + generateFor: Set.from(['$_pkgName|lib/a.dart']), outputs: { '$_pkgName|lib/a.foo.g.part': decodedMatches( contains(UnformattedCodeGenerator.formattedCode)), @@ -234,12 +233,12 @@ void main() { test('does not output files which contain `part of`', () async { await testBuilder( - new SharedPartBuilder( + SharedPartBuilder( [const UnformattedCodeGenerator()], 'foo', ), {'$_pkgName|lib/a.dart': 'library a; part "a.g.dart";'}, - generateFor: new Set.from(['$_pkgName|lib/a.dart']), + generateFor: Set.from(['$_pkgName|lib/a.dart']), outputs: { '$_pkgName|lib/a.foo.g.part': decodedMatches(isNot(contains('part of'))), @@ -257,7 +256,7 @@ void main() { }.entries) { test('throws if the partId ${entry.key}', () async { expect( - () => new SharedPartBuilder( + () => SharedPartBuilder( [const UnformattedCodeGenerator()], entry.value, ), @@ -270,12 +269,12 @@ void main() { group('CombiningBuilder', () { test('includes a generated code header', () async { await testBuilder( - new CombiningBuilder(), + CombiningBuilder(), { '$_pkgName|lib/a.dart': 'library a; part "a.g.dart";', '$_pkgName|lib/a.foo.g.part': 'some generated content' }, - generateFor: new Set.from(['$_pkgName|lib/a.dart']), + generateFor: Set.from(['$_pkgName|lib/a.dart']), outputs: { '$_pkgName|lib/a.g.dart': decodedMatches( startsWith('// GENERATED CODE - DO NOT MODIFY BY HAND')), @@ -284,12 +283,12 @@ void main() { test('outputs `.g.dart` files', () async { await testBuilder( - new CombiningBuilder(), + CombiningBuilder(), { '$_pkgName|lib/a.dart': 'library a; part "a.g.dart";', '$_pkgName|lib/a.foo.g.part': 'some generated content' }, - generateFor: new Set.from(['$_pkgName|lib/a.dart']), + generateFor: Set.from(['$_pkgName|lib/a.dart']), outputs: { '$_pkgName|lib/a.g.dart': decodedMatches(endsWith('some generated content\n')), @@ -298,12 +297,12 @@ void main() { test('outputs contain `part of`', () async { await testBuilder( - new CombiningBuilder(), + CombiningBuilder(), { '$_pkgName|lib/a.dart': 'library a; part "a.g.dart";', '$_pkgName|lib/a.foo.g.part': 'some generated content' }, - generateFor: new Set.from(['$_pkgName|lib/a.dart']), + generateFor: Set.from(['$_pkgName|lib/a.dart']), outputs: { '$_pkgName|lib/a.g.dart': decodedMatches(contains('part of')), }); @@ -311,13 +310,13 @@ void main() { test('joins part files', () async { await testBuilder( - new CombiningBuilder(), + CombiningBuilder(), { '$_pkgName|lib/a.dart': 'library a; part "a.g.dart";', '$_pkgName|lib/a.foo.g.part': 'foo generated content', '$_pkgName|lib/a.bar.g.part': 'bar generated content', }, - generateFor: new Set.from(['$_pkgName|lib/a.dart']), + generateFor: Set.from(['$_pkgName|lib/a.dart']), outputs: { '$_pkgName|lib/a.g.dart': decodedMatches(endsWith( '\n\nbar generated content\n\nfoo generated content\n')), @@ -326,14 +325,14 @@ void main() { test('joins only associated part files', () async { await testBuilder( - new CombiningBuilder(), + CombiningBuilder(), { '$_pkgName|lib/a.dart': 'library a; part "a.g.dart";', '$_pkgName|lib/a.foo.g.part': 'foo generated content', '$_pkgName|lib/a.bar.g.part': 'bar generated content', '$_pkgName|lib/a.bar.other.g.part': 'bar.other generated content', }, - generateFor: new Set.from(['$_pkgName|lib/a.dart']), + generateFor: Set.from(['$_pkgName|lib/a.dart']), outputs: { '$_pkgName|lib/a.g.dart': decodedMatches( endsWith('bar generated content\n\nfoo generated content\n')), @@ -342,25 +341,25 @@ void main() { test('outputs nothing if no part files are found', () async { await testBuilder( - new CombiningBuilder(), + CombiningBuilder(), { '$_pkgName|lib/a.dart': 'library a; part "a.g.dart";', }, - generateFor: new Set.from(['$_pkgName|lib/a.dart']), + generateFor: Set.from(['$_pkgName|lib/a.dart']), outputs: {}); }); test('trims part content and skips empty and whitespace-only parts', () async { await testBuilder( - new CombiningBuilder(), + CombiningBuilder(), { '$_pkgName|lib/a.dart': 'library a; part "a.g.dart";', '$_pkgName|lib/a.foo.g.part': '\n\nfoo generated content\n', '$_pkgName|lib/a.only_whitespace.g.part': '\n\n\t \n \n', '$_pkgName|lib/a.bar.g.part': '\nbar generated content', }, - generateFor: new Set.from(['$_pkgName|lib/a.dart']), + generateFor: Set.from(['$_pkgName|lib/a.dart']), outputs: { '$_pkgName|lib/a.g.dart': decodedMatches(endsWith( '\n\nbar generated content\n\nfoo generated content\n')), @@ -369,14 +368,14 @@ void main() { test('includes part header if enabled', () async { await testBuilder( - new CombiningBuilder(includePartName: true), + CombiningBuilder(includePartName: true), { '$_pkgName|lib/a.dart': 'library a; part "a.g.dart";', '$_pkgName|lib/a.foo.g.part': '\n\nfoo generated content\n', '$_pkgName|lib/a.only_whitespace.g.part': '\n\n\t \n \n', '$_pkgName|lib/a.bar.g.part': '\nbar generated content', }, - generateFor: new Set.from(['$_pkgName|lib/a.dart']), + generateFor: Set.from(['$_pkgName|lib/a.dart']), outputs: { '$_pkgName|lib/a.g.dart': decodedMatches(endsWith('\n\n' '// Part: a.bar.g.part\n' @@ -390,10 +389,10 @@ void main() { test('can skip formatting with a trivial lambda', () async { await testBuilder( - new PartBuilder([const UnformattedCodeGenerator()], '.foo.dart', + PartBuilder([const UnformattedCodeGenerator()], '.foo.dart', formatOutput: (s) => s), {'$_pkgName|lib/a.dart': 'library a; part "a.part.dart";'}, - generateFor: new Set.from(['$_pkgName|lib/a.dart']), + generateFor: Set.from(['$_pkgName|lib/a.dart']), outputs: { '$_pkgName|lib/a.foo.dart': decodedMatches( contains(UnformattedCodeGenerator.unformattedCode)), @@ -403,20 +402,20 @@ void main() { test('can pass a custom formatter with formatOutput', () async { var customOutput = 'final String hello = "hello";'; await testBuilder( - new PartBuilder([const UnformattedCodeGenerator()], '.foo.dart', + PartBuilder([const UnformattedCodeGenerator()], '.foo.dart', formatOutput: (_) => customOutput), {'$_pkgName|lib/a.dart': 'library a; part "a.part.dart";'}, - generateFor: new Set.from(['$_pkgName|lib/a.dart']), + generateFor: Set.from(['$_pkgName|lib/a.dart']), outputs: { '$_pkgName|lib/a.foo.dart': decodedMatches(contains(customOutput)), }); }); test('Should have a readable toString() message for builders', () { - final builder = new LibraryBuilder(const _LiteralGenerator()); + final builder = LibraryBuilder(const _LiteralGenerator()); expect(builder.toString(), 'Generating .g.dart: _LiteralGenerator'); - final builders = new PartBuilder([ + final builders = PartBuilder([ const _LiteralGenerator(), const _LiteralGenerator(), ], '.foo.dart'); @@ -427,10 +426,10 @@ void main() { Future _generateTest(CommentGenerator gen, String expectedContent) async { var srcs = _createPackageStub(); - var builder = new PartBuilder([gen], '.foo.dart'); + var builder = PartBuilder([gen], '.foo.dart'); await testBuilder(builder, srcs, - generateFor: new Set.from(['$_pkgName|lib/test_lib.dart']), + generateFor: Set.from(['$_pkgName|lib/test_lib.dart']), outputs: { '$_pkgName|lib/test_lib.foo.dart': decodedMatches(expectedContent), }, @@ -447,7 +446,7 @@ Map _createPackageStub( } PartBuilder _unformattedLiteral([String content]) => - new PartBuilder([new _LiteralGenerator(content)], '.foo.dart', + PartBuilder([_LiteralGenerator(content)], '.foo.dart', formatOutput: (s) => s); /// Returns the [String] provided in the constructor, or `null`. diff --git a/source_gen/test/constants_test.dart b/source_gen/test/constants_test.dart index 70accb9b..9ded565d 100644 --- a/source_gen/test/constants_test.dart +++ b/source_gen/test/constants_test.dart @@ -60,7 +60,7 @@ void main() { constants = library .getType('Example') .metadata - .map((e) => new ConstantReader(e.computeConstantValue())) + .map((e) => ConstantReader(e.computeConstantValue())) .toList(); }); @@ -116,7 +116,7 @@ void main() { test('should read a list', () { expect(constants[6].isList, isTrue, reason: '${constants[6]}'); expect(constants[6].isLiteral, isTrue); - expect(constants[6].listValue.map((c) => new ConstantReader(c).intValue), + expect(constants[6].listValue.map((c) => ConstantReader(c).intValue), [1, 2, 3]); }); @@ -125,8 +125,8 @@ void main() { expect(constants[7].isLiteral, isTrue); expect( mapMap(constants[7].mapValue, - key: (k, _) => new ConstantReader(k).intValue, - value: (_, v) => new ConstantReader(v).stringValue), + key: (k, _) => ConstantReader(k).intValue, + value: (_, v) => ConstantReader(v).stringValue), {1: 'A', 2: 'B'}); }); @@ -252,7 +252,7 @@ void main() { constants = library .getType('Example') .metadata - .map((e) => new ConstantReader(e.computeConstantValue())) + .map((e) => ConstantReader(e.computeConstantValue())) .toList(); }); @@ -268,7 +268,7 @@ void main() { expect(duration30s.accessor, isEmpty); expect( mapMap(duration30s.namedArguments, - value: (_, DartObject v) => new ConstantReader(v).literalValue), + value: (_, DartObject v) => ConstantReader(v).literalValue), { 'seconds': 30, }); diff --git a/source_gen/test/generator_for_annotation_test.dart b/source_gen/test/generator_for_annotation_test.dart index 32b66829..f8e43375 100644 --- a/source_gen/test/generator_for_annotation_test.dart +++ b/source_gen/test/generator_for_annotation_test.dart @@ -22,8 +22,8 @@ void main() { 'list with null, empty, and whitespace items': [null, '', '\n \t'] }.entries) { test(entry.key, () async { - final generator = new LiteralOutput(entry.value); - var builder = new LibraryBuilder(generator); + final generator = LiteralOutput(entry.value); + var builder = LibraryBuilder(generator); await testBuilder(builder, _inputMap, outputs: {}); }); } @@ -31,7 +31,7 @@ void main() { test('Supports and dedupes multiple return values', () async { final generator = const RepeatingGenerator(); - var builder = new LibraryBuilder(generator); + var builder = LibraryBuilder(generator); await testBuilder(builder, _inputMap, outputs: { 'a|lib/file.g.dart': r''' // GENERATED CODE - DO NOT MODIFY BY HAND @@ -57,7 +57,7 @@ void main() { 'from iterable': const FailingIterableGenerator() }.entries) { test(entry.key, () async { - var builder = new LibraryBuilder(entry.value); + var builder = LibraryBuilder(entry.value); await testBuilder(builder, _inputMap, outputs: { 'a|lib/file.g.dart': r''' // GENERATED CODE - DO NOT MODIFY BY HAND @@ -81,7 +81,7 @@ class FailingIterableGenerator extends GeneratorForAnnotation { Iterable generateForAnnotatedElement( Element element, ConstantReader annotation, BuildStep buildStep) sync* { yield '// There are deprecated values in this library!'; - throw new StateError('not supported!'); + throw StateError('not supported!'); } @override @@ -94,7 +94,7 @@ class FailingGenerator extends GeneratorForAnnotation { @override generateForAnnotatedElement( Element element, ConstantReader annotation, BuildStep buildStep) { - throw new StateError('not supported!'); + throw StateError('not supported!'); } } @@ -121,7 +121,7 @@ class LiteralOutput extends GeneratorForAnnotation { null; } -const _inputMap = const { +const _inputMap = { 'a|lib/file.dart': ''' @deprecated final foo = 'foo'; diff --git a/source_gen/test/library/find_type_test.dart b/source_gen/test/library/find_type_test.dart index 7ffbf8d4..793cd676 100644 --- a/source_gen/test/library/find_type_test.dart +++ b/source_gen/test/library/find_type_test.dart @@ -31,7 +31,7 @@ void main() { setUpAll(() async { library = await resolveSources( {'a|source.dart': _source, 'a|part.dart': _partSource}, - (r) async => new LibraryReader(await r.findLibraryByName('test_lib')), + (r) async => LibraryReader(await r.findLibraryByName('test_lib')), ); }); diff --git a/source_gen/test/library/path_to_url_test.dart b/source_gen/test/library/path_to_url_test.dart index 5437d4f1..f4bcdd1d 100644 --- a/source_gen/test/library/path_to_url_test.dart +++ b/source_gen/test/library/path_to_url_test.dart @@ -24,7 +24,7 @@ void main() { group('from a package URL to', () { setUpAll(() { - reader = new LibraryReader(new _FakeLibraryElement(packageA)); + reader = LibraryReader(_FakeLibraryElement(packageA)); }); test('a dart SDK library', () { @@ -62,7 +62,7 @@ void main() { group('from an asset URL representing a package to', () { setUpAll(() { - reader = new LibraryReader(new _FakeLibraryElement(assetPackageA)); + reader = LibraryReader(_FakeLibraryElement(assetPackageA)); }); test('a dart SDK library', () { @@ -100,7 +100,7 @@ void main() { group('from an asset URL representing a test directory to', () { setUpAll(() { - reader = new LibraryReader(new _FakeLibraryElement(packageATestDir)); + reader = LibraryReader(_FakeLibraryElement(packageATestDir)); }); test('a dart SDK library', () { @@ -143,8 +143,8 @@ void main() { }); test('in the same package in the test directory, a shallow file', () { - reader = new LibraryReader( - new _FakeLibraryElement(packageATestDirDeepFile), + reader = LibraryReader( + _FakeLibraryElement(packageATestDirDeepFile), ); expect( reader.pathToUrl(packageATestDir), @@ -172,7 +172,7 @@ class _FakeLibraryElement implements LibraryElement { noSuchMethod(i) => super.noSuchMethod(i); @override - Source get source => new _FakeSource(_sourceUri); + Source get source => _FakeSource(_sourceUri); } class _FakeSource implements Source { diff --git a/source_gen/test/output_helpers_test.dart b/source_gen/test/output_helpers_test.dart index 8465241f..062b4c7b 100644 --- a/source_gen/test/output_helpers_test.dart +++ b/source_gen/test/output_helpers_test.dart @@ -13,11 +13,11 @@ void main() { _testSimpleValue('String', 'string', ['string']); _testSimpleValue('empty List', [], []); _testSimpleValue('List', ['a', 'b', 'c'], ['a', 'b', 'c']); - _testSimpleValue('Iterable', new Iterable.generate(3, (i) => i.toString()), - ['0', '1', '2']); + _testSimpleValue( + 'Iterable', Iterable.generate(3, (i) => i.toString()), ['0', '1', '2']); _testFunction('Future', - new Future.value(new Stream.fromIterable(['value'])), ['value']); + Future.value(Stream.fromIterable(['value'])), ['value']); }); group('invalid values', () { @@ -25,24 +25,22 @@ void main() { _testSimpleValue( 'mixed good and bad', ['good', 42, 'also good'], throwsArgumentError); - var badInstance = new _ThrowOnToString(); + var badInstance = _ThrowOnToString(); _testSimpleValue('really bad class', badInstance, throwsArgumentError); _testSimpleValue( 'iterable with errors', _throwingIterable(), throwsArgumentError); - _testFunction('sync throw', () => throw new ArgumentError('Error message'), + _testFunction('sync throw', () => throw ArgumentError('Error message'), throwsArgumentError); _testFunction( 'new Future.error', - () => new Future.error(new ArgumentError('Error message')), + () => Future.error(ArgumentError('Error message')), throwsArgumentError); - _testFunction( - 'throw in async', - () async => throw new ArgumentError('Error message'), - throwsArgumentError); + _testFunction('throw in async', + () async => throw ArgumentError('Error message'), throwsArgumentError); }); } @@ -51,14 +49,14 @@ void _testSimpleValue(String testName, Object value, expected) { assert(value is! Future); - _testFunction('Future<$testName>', new Future.value(value), expected); + _testFunction('Future<$testName>', Future.value(value), expected); if (value is Iterable) { _testFunction('Stream with values from $testName', - new Stream.fromIterable(value), expected); + Stream.fromIterable(value), expected); } else { - _testFunction('Stream single value $testName', - new Stream.fromIterable([value]), expected); + _testFunction('Stream single value $testName', Stream.fromIterable([value]), + expected); } } @@ -75,12 +73,12 @@ void _testFunction(String testName, value, expected) { Iterable _throwingIterable() sync* { yield 'a'; yield 'b'; - throw new ArgumentError('Error in iterator!'); + throw ArgumentError('Error in iterator!'); } class _ThrowOnToString { @override String toString() { - throw new UnsupportedError('cannot call toString'); + throw UnsupportedError('cannot call toString'); } } diff --git a/source_gen/test/span_for_element_test.dart b/source_gen/test/span_for_element_test.dart index 875ba84d..97f785af 100644 --- a/source_gen/test/span_for_element_test.dart +++ b/source_gen/test/span_for_element_test.dart @@ -17,7 +17,7 @@ void main() { abstract class Example implements List {} ''', (resolver) => resolver.findLibraryByName('test_lib'), - inputId: new AssetId('test_lib', 'lib/test_lib.dart')); + inputId: AssetId('test_lib', 'lib/test_lib.dart')); }); test('should highlight the use of "class Example"', () { diff --git a/source_gen/test/src/comment_generator.dart b/source_gen/test/src/comment_generator.dart index b93d10c6..15601902 100644 --- a/source_gen/test/src/comment_generator.dart +++ b/source_gen/test/src/comment_generator.dart @@ -27,7 +27,7 @@ class CommentGenerator extends Generator { for (var classElement in library.allElements.where((e) => e is ClassElement)) { if (classElement.displayName.contains('GoodError')) { - throw new InvalidGenerationSourceError( + throw InvalidGenerationSourceError( "Don't use classes with the word 'Error' in the name", todo: 'Rename ${classElement.displayName} to something else.', element: classElement); diff --git a/source_gen/test/test_files/annotated_classes.dart b/source_gen/test/test_files/annotated_classes.dart index ffb2d273..defb6f5f 100644 --- a/source_gen/test/test_files/annotated_classes.dart +++ b/source_gen/test/test_files/annotated_classes.dart @@ -10,10 +10,9 @@ import 'annotations.dart'; part 'annotated_classes_part.dart'; -const localUntypedAnnotation = const PublicAnnotationClass(); +const localUntypedAnnotation = PublicAnnotationClass(); -const PublicAnnotationClass localTypedAnnotation = - const PublicAnnotationClass(); +const PublicAnnotationClass localTypedAnnotation = PublicAnnotationClass(); @PublicAnnotationClass() class CtorNoParams {} @@ -31,7 +30,7 @@ class NonDefaultCtorNoParams {} class NonDefaultCtorWithPositionalParams {} @PublicAnnotationClass.withPositionalArgs(43, 'another value', - boolArg: true, listArg: const [5, 6, 7]) + boolArg: true, listArg: [5, 6, 7]) class NonDefaultCtorWithPositionalAndNamedParams {} @PublicAnnotationClass.withKids() diff --git a/source_gen/test/test_files/annotated_classes_part.dart b/source_gen/test/test_files/annotated_classes_part.dart index 8a2bfe56..106aa557 100644 --- a/source_gen/test/test_files/annotated_classes_part.dart +++ b/source_gen/test/test_files/annotated_classes_part.dart @@ -4,10 +4,10 @@ part of source_gen.test.annotation_test.classes; -const localUntypedAnnotationInPart = const PublicAnnotationClass(); +const localUntypedAnnotationInPart = PublicAnnotationClass(); const PublicAnnotationClass localTypedAnnotationInPart = - const PublicAnnotationClass(); + PublicAnnotationClass(); @PublicAnnotationClass() class CtorNoParamsInPart {} diff --git a/source_gen/test/test_files/annotations.dart b/source_gen/test/test_files/annotations.dart index 9af00292..be6dd090 100644 --- a/source_gen/test/test_files/annotations.dart +++ b/source_gen/test/test_files/annotations.dart @@ -7,12 +7,12 @@ import 'dart:collection' as collection; part 'annotation_part.dart'; -const untypedAnnotation = const PublicAnnotationClass(); +const untypedAnnotation = PublicAnnotationClass(); const untypedAnnotationWithNonDefaultCtor = - const PublicAnnotationClass.withPositionalArgs(5, 'field', boolArg: true); + PublicAnnotationClass.withPositionalArgs(5, 'field', boolArg: true); -const PublicAnnotationClass typedAnnotation = const PublicAnnotationClass(); +const PublicAnnotationClass typedAnnotation = PublicAnnotationClass(); class PublicAnnotationClass { final int anInt; @@ -59,10 +59,10 @@ class OtherPublicAnnotationClass { const OtherPublicAnnotationClass(); } -const objectAnnotation = const { +const objectAnnotation = { 'int': 1, 'bool': true, - 'list': const [1, 2, 3], + 'list': [1, 2, 3], 'symbol': #foo, 'double': 3.14, 'null': null, diff --git a/source_gen/test/type_checker_test.dart b/source_gen/test/type_checker_test.dart index fe48f1f4..efa76660 100644 --- a/source_gen/test/type_checker_test.dart +++ b/source_gen/test/type_checker_test.dart @@ -39,27 +39,27 @@ void main() { ''', (resolver) async { core = await resolver.findLibraryByName('dart.core'); collection = await resolver.findLibraryByName('dart.collection'); - sourceGen = new LibraryReader(await resolver.libraryFor( - new AssetId.resolve('asset:source_gen/lib/source_gen.dart'))); + sourceGen = LibraryReader(await resolver + .libraryFor(AssetId.resolve('asset:source_gen/lib/source_gen.dart'))); }); var staticIterable = core.getType('Iterable').type; - staticIterableChecker = new TypeChecker.fromStatic(staticIterable); + staticIterableChecker = TypeChecker.fromStatic(staticIterable); staticUri = core.getType('Uri').type; staticMap = core.getType('Map').type; - staticMapChecker = new TypeChecker.fromStatic(staticMap); + staticMapChecker = TypeChecker.fromStatic(staticMap); staticHashMap = collection.getType('HashMap').type; - staticHashMapChecker = new TypeChecker.fromStatic(staticHashMap); + staticHashMapChecker = TypeChecker.fromStatic(staticHashMap); staticUnmodifiableListView = collection.getType('UnmodifiableListView').type; staticGenerator = sourceGen.findType('Generator').type; - staticGeneratorChecker = new TypeChecker.fromStatic(staticGenerator); + staticGeneratorChecker = TypeChecker.fromStatic(staticGenerator); staticGeneratorForAnnotation = sourceGen.findType('GeneratorForAnnotation').type; staticGeneratorForAnnotationChecker = - new TypeChecker.fromStatic(staticGeneratorForAnnotation); + TypeChecker.fromStatic(staticGeneratorForAnnotation); }); // Run a common set of type comparison checks with various implementations. @@ -206,9 +206,9 @@ void main() { }); test('should check multiple checkers', () { - final listOrMap = const TypeChecker.any(const [ - const TypeChecker.fromRuntime(List), - const TypeChecker.fromRuntime(Map), + final listOrMap = const TypeChecker.any([ + TypeChecker.fromRuntime(List), + TypeChecker.fromRuntime(Map), ]); expect(listOrMap.isExactlyType(staticMap), isTrue); }); @@ -254,9 +254,9 @@ void main() { const C(); } ''', (resolver) => resolver.findLibraryByName('_test')); - $A = new TypeChecker.fromStatic(library.getType('A').type); - $B = new TypeChecker.fromStatic(library.getType('B').type); - $C = new TypeChecker.fromStatic(library.getType('C').type); + $A = TypeChecker.fromStatic(library.getType('A').type); + $B = TypeChecker.fromStatic(library.getType('B').type); + $C = TypeChecker.fromStatic(library.getType('C').type); $ExampleOfA = library.getType('ExampleOfA'); $ExampleOfMultiA = library.getType('ExampleOfMultiA'); $ExampleOfAPlusB = library.getType('ExampleOfAPlusB'); @@ -314,7 +314,7 @@ void main() { const A(); } ''', (resolver) => resolver.findLibraryByName('_test')); - $A = new TypeChecker.fromStatic(library.getType('A').type); + $A = TypeChecker.fromStatic(library.getType('A').type); $ExampleOfA = library.getType('ExampleOfA'); });