From cacaa75d5d21416ffcc43a15ddd1c1c532dffd85 Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Thu, 27 Oct 2016 00:55:52 -0700 Subject: [PATCH] Address comments. Address comments and presubmit script. . --- .travis.yml | 2 +- README.md | 2 +- lib/code_builder.dart | 15 ------------- lib/dart/async.dart | 12 +++++----- lib/dart/core.dart | 8 +++---- lib/src/builders/annotation.dart | 4 ++-- lib/src/builders/class.dart | 4 ++-- lib/src/builders/expression.dart | 16 +++++++++++--- lib/src/builders/expression/assign.dart | 7 +++--- lib/src/builders/expression/negate.dart | 17 +++++++++++++++ lib/src/builders/field.dart | 4 ++-- lib/src/builders/file.dart | 4 ++-- lib/src/builders/method.dart | 4 ++-- lib/src/builders/parameter.dart | 2 +- lib/src/builders/type.dart | 4 ++-- lib/src/builders/type/new_instance.dart | 4 ++-- lib/src/pretty_printer.dart | 12 +++++++++- lib/src/scope.dart | 8 +++---- lib/testing.dart | 1 + test/builders/class_test.dart | 24 ++++++++++---------- test/builders/expression_test.dart | 4 ++-- test/builders/field_test.dart | 6 ++--- test/builders/method_test.dart | 10 ++++----- test/builders/statement_test.dart | 16 +++++++------- test/builders/type_test.dart | 9 ++++---- test/e2e_test.dart | 4 ++-- tool/presubmit.sh | 29 +++++++++++++++++++++++++ 27 files changed, 143 insertions(+), 89 deletions(-) create mode 100755 tool/presubmit.sh diff --git a/.travis.yml b/.travis.yml index 5826f9b..08997a6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,4 +4,4 @@ dart: - dev - stable -script: ./tool/travis.sh +script: ./tool/presubmit.sh diff --git a/README.md b/README.md index 297b8b7..df51b80 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ var clazz = new ClassBuilder('Animal', asExtends: base); clazz.addMethod( new MethodBuilder.returnVoid( 'eat', - returns: reference('print).call([literal('Yum')]), + returns: reference('print').call([literal('Yum')]), ), ); ``` diff --git a/lib/code_builder.dart b/lib/code_builder.dart index 4506474..9506468 100644 --- a/lib/code_builder.dart +++ b/lib/code_builder.dart @@ -2,9 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:dart_style/dart_style.dart'; -import 'package:meta/meta.dart'; - export 'src/builders/annotation.dart' show AnnotationBuilder; export 'src/builders/class.dart' show asStatic, clazz, extend, implement, mixin, ClassBuilder; @@ -34,15 +31,3 @@ export 'src/builders/shared.dart' show AstBuilder, Scope; export 'src/builders/statement.dart' show ifThen, elseIf, elseThen, IfStatementBuilder, StatementBuilder; export 'src/builders/type.dart' show NewInstanceBuilder, TypeBuilder; - -final _dartFmt = new DartFormatter(); - -/// Returns [source] formatted by `dartfmt`. -@visibleForTesting -String dartfmt(String source) { - try { - return _dartFmt.format(source); - } on FormatterException catch (_) { - return _dartFmt.formatStatement(source); - } -} diff --git a/lib/dart/async.dart b/lib/dart/async.dart index fcb51b6..6025c39 100644 --- a/lib/dart/async.dart +++ b/lib/dart/async.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -/// Contains reference to the `dart:async` SDK for use in code generation. +/// Contains references to the `dart:async` SDK for use in code generation. /// /// This library is currently *experimental*, and is subject to change; it is /// currently manually maintained but there might be a strong use case for this @@ -14,11 +14,11 @@ /// import 'package:code_builder/code_builder.dart'; /// import 'package:code_builder/dart/async.dart'; /// -/// All references are _namespaced_ under [async]. Try it: +/// All references are _namespaced_ under [lib$async]. Try it: /// // Outputs: new Future.value('Hello') /// async.Future.newInstanceNamed('value', [literal('Hello')]); /// -/// If you are [missing a reference from `dart:async`](https://goo.gl/XbSfmT) +/// If you are [missing a symbol from `dart:async`](https://goo.gl/XbSfmT) /// please send us a [pull request](https://goo.gl/2LvV7f) or /// [file an issue](https://goo.gl/IooPfl). library code_builder.dart.async; @@ -27,10 +27,10 @@ import 'dart:async' as dart_async; import 'package:code_builder/code_builder.dart'; -/// A namespace for references in `dart:async`. -final DartAsync async = new DartAsync._(); +/// References to `dart:async`. +final DartAsync lib$async = new DartAsync._(); -/// References to the `dart:async` library for code generation. See [async]. +/// References to the `dart:async` library for code generation. See [lib$async]. class DartAsync { /// References [dart_async.Future]. final ReferenceBuilder Future = _ref('Future'); diff --git a/lib/dart/core.dart b/lib/dart/core.dart index 21e97b3..9a5a0d7 100644 --- a/lib/dart/core.dart +++ b/lib/dart/core.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -/// Contains reference to the `dart:core` SDK for use in code generation. +/// Contains references to the `dart:core` SDK for use in code generation. /// /// This library is currently *experimental*, and is subject to change; it is /// currently manually maintained but there might be a strong use case for this @@ -14,7 +14,7 @@ /// import 'package:code_builder/code_builder.dart'; /// import 'package:code_builder/dart/core.dart'; /// -/// All references are _namespaced_ under [core]. Try it: +/// All references are _namespaced_ under [lib$core]. Try it: /// // Outputs: print('Hello World') /// core.print.call([literal('Hello World')]); /// @@ -28,9 +28,9 @@ import 'dart:core' as dart_core; import 'package:code_builder/code_builder.dart'; /// A namespace for references in `dart:core`. -final DartCore core = new DartCore._(); +final DartCore lib$core = new DartCore._(); -/// References to the `dart:core` library for code generation. See [core]. +/// References to the `dart:core` library for code generation. See [lib$core]. class DartCore { /// References [dart_core.bool]. final ReferenceBuilder bool = _ref('bool'); diff --git a/lib/src/builders/annotation.dart b/lib/src/builders/annotation.dart index eb68c15..404088a 100644 --- a/lib/src/builders/annotation.dart +++ b/lib/src/builders/annotation.dart @@ -7,7 +7,7 @@ import 'package:code_builder/src/builders/class.dart'; import 'package:code_builder/src/builders/parameter.dart'; import 'package:code_builder/src/builders/shared.dart'; -/// Lazily builds an [Annotation] AST when [buildAnnotation] is invoked. +/// Builds an [Annotation] AST when [buildAnnotation] is invoked. abstract class AnnotationBuilder implements ValidClassMember, ValidParameterMember { /// Returns an [Annotation] AST representing the builder. @@ -43,7 +43,7 @@ abstract class HasAnnotationsMixin implements HasAnnotations { .toList(); /// Clones all annotations to [clone]. - void cloneAnnotationsTo(HasAnnotations clone) { + void copyAnnotationsTo(HasAnnotations clone) { clone.addAnnotations(_annotations); } } diff --git a/lib/src/builders/class.dart b/lib/src/builders/class.dart index 5a035a5..333d3e4 100644 --- a/lib/src/builders/class.dart +++ b/lib/src/builders/class.dart @@ -49,7 +49,7 @@ ClassBuilder clazz( } /// Wrap [member] to be emitted as a `static` method or field. -_StaticFieldWrapper asStatic(ValidClassMember member) { +ValidClassMember asStatic(ValidClassMember member) { return new _StaticFieldWrapper(member); } @@ -198,7 +198,7 @@ class _ClassBuilderImpl extends Object ClassDeclaration buildClass([Scope scope]) { var extend = _extends; if (extend == null && _with.isNotEmpty) { - extend = core.Object; + extend = lib$core.Object; } final clazz = new ClassDeclaration( null, diff --git a/lib/src/builders/expression.dart b/lib/src/builders/expression.dart index 815cdb4..9b3b289 100644 --- a/lib/src/builders/expression.dart +++ b/lib/src/builders/expression.dart @@ -109,7 +109,11 @@ abstract class AbstractExpressionMixin implements ExpressionBuilder { StatementBuilder asAssert() => new _AsAssert(this); @override - StatementBuilder asAssign(String variable) => new _AsAssign(this, variable); + StatementBuilder asAssign( + String variable, { + bool nullAware: false, + }) => + new _AsAssign(this, variable, nullAware); @override StatementBuilder asConst(String variable, [TypeBuilder type]) { @@ -162,7 +166,7 @@ abstract class AbstractExpressionMixin implements ExpressionBuilder { @override ExpressionBuilder identical(ExpressionBuilder other) { - return core.identical.call([ + return lib$core.identical.call([ this, other, ]); @@ -183,6 +187,9 @@ abstract class AbstractExpressionMixin implements ExpressionBuilder { @override ExpressionBuilder negate() => new _NegateExpression(this); + @override + ExpressionBuilder negative() => new _NegativeExpression(this); + @override ExpressionBuilder notEquals(ExpressionBuilder other) { return new _AsBinaryExpression( @@ -196,7 +203,7 @@ abstract class AbstractExpressionMixin implements ExpressionBuilder { ExpressionBuilder parentheses() => new _ParenthesesExpression(this); } -/// Lazily builds an [Expression] AST when [buildExpression] is invoked. +/// Builds an [Expression] AST when [buildExpression] is invoked. abstract class ExpressionBuilder implements AstBuilder, StatementBuilder, ValidParameterMember { /// Returns as an [ExpressionBuilder] multiplying by [other]. @@ -266,6 +273,9 @@ abstract class ExpressionBuilder /// Returns as an [ExpressionBuilder] negating using the `!` operator. ExpressionBuilder negate(); + /// Returns as an [ExpressionBuilder] negating the value, + ExpressionBuilder negative(); + /// Returns as an [ExpressionBuilder] comparing using `!=` against [other]. ExpressionBuilder notEquals(ExpressionBuilder other); diff --git a/lib/src/builders/expression/assign.dart b/lib/src/builders/expression/assign.dart index 168eb73..5c6b191 100644 --- a/lib/src/builders/expression/assign.dart +++ b/lib/src/builders/expression/assign.dart @@ -1,10 +1,11 @@ part of code_builder.src.builders.expression; class _AsAssign extends AbstractExpressionMixin { - final ExpressionBuilder _value; final String _name; + final bool _nullAware; + final ExpressionBuilder _value; - _AsAssign(this._value, this._name); + _AsAssign(this._value, this._name, this._nullAware); @override AstNode buildAst([Scope scope]) => buildExpression(scope); @@ -13,7 +14,7 @@ class _AsAssign extends AbstractExpressionMixin { Expression buildExpression([Scope scope]) { return new AssignmentExpression( stringIdentifier(_name), - $equals, + _nullAware ? $nullAwareEquals : $equals, _value.buildExpression(scope), ); } diff --git a/lib/src/builders/expression/negate.dart b/lib/src/builders/expression/negate.dart index 1bac44b..d1d58d3 100644 --- a/lib/src/builders/expression/negate.dart +++ b/lib/src/builders/expression/negate.dart @@ -16,3 +16,20 @@ class _NegateExpression extends AbstractExpressionMixin { ); } } + +class _NegativeExpression extends AbstractExpressionMixin { + final ExpressionBuilder _expression; + + _NegativeExpression(this._expression); + + @override + AstNode buildAst([Scope scope]) => buildExpression(scope); + + @override + Expression buildExpression([Scope scope]) { + return new PrefixExpression( + $minus, + _expression.parentheses().buildExpression(scope), + ); + } +} diff --git a/lib/src/builders/field.dart b/lib/src/builders/field.dart index 0286646..51b5d97 100644 --- a/lib/src/builders/field.dart +++ b/lib/src/builders/field.dart @@ -22,7 +22,7 @@ FieldBuilder varField( ); } -/// Short-hand for [FieldBuilder]. +/// Short-hand for [FieldBuilder.asFinal]. FieldBuilder varFinal( String name, { TypeBuilder type, @@ -35,7 +35,7 @@ FieldBuilder varFinal( ); } -/// Short-hand for [FieldBuilder]. +/// Short-hand for [FieldBuilder.asConst]. FieldBuilder varConst( String name, { TypeBuilder type, diff --git a/lib/src/builders/file.dart b/lib/src/builders/file.dart index dd82969..fc6e71b 100644 --- a/lib/src/builders/file.dart +++ b/lib/src/builders/file.dart @@ -6,7 +6,7 @@ import 'package:analyzer/analyzer.dart'; import 'package:code_builder/src/builders/shared.dart'; import 'package:code_builder/src/tokens.dart'; -/// Lazily builds a file of Dart source code. +/// Builds a file of Dart source code. /// /// See [LibraryBuilder] and [PartBuilder] for concrete implementations. abstract class FileBuilder implements AstBuilder { @@ -26,7 +26,7 @@ abstract class FileBuilder implements AstBuilder { } } -/// Lazily builds a standalone file (library) of Dart source code. +/// Builds a standalone file (library) of Dart source code. class LibraryBuilder extends FileBuilder { final List> _directives = >[]; final Scope _scope; diff --git a/lib/src/builders/method.dart b/lib/src/builders/method.dart index 4461486..2228d2f 100644 --- a/lib/src/builders/method.dart +++ b/lib/src/builders/method.dart @@ -209,12 +209,12 @@ abstract class MethodBuilder /// Creates a new [MethodBuilder] that returns `void`. factory MethodBuilder.returnVoid(String name, {ExpressionBuilder returns}) { if (returns == null) { - return new _MethodBuilderImpl(name, returns: core.$void); + return new _MethodBuilderImpl(name, returns: lib$core.$void); } return new _LambdaMethodBuilder( name, returns, - core.$void, + lib$core.$void, null, ); } diff --git a/lib/src/builders/parameter.dart b/lib/src/builders/parameter.dart index c37ae27..58df28e 100644 --- a/lib/src/builders/parameter.dart +++ b/lib/src/builders/parameter.dart @@ -10,7 +10,7 @@ import 'package:code_builder/src/builders/shared.dart'; import 'package:code_builder/src/builders/type.dart'; import 'package:code_builder/src/tokens.dart'; -/// A more short-hand way of constructing a [ParameterBuilder]. +/// A short-hand way of constructing a [ParameterBuilder]. ParameterBuilder parameter( String name, [ Iterable members = const [], diff --git a/lib/src/builders/type.dart b/lib/src/builders/type.dart index 34d21ba..c4eae10 100644 --- a/lib/src/builders/type.dart +++ b/lib/src/builders/type.dart @@ -29,7 +29,7 @@ abstract class AbstractTypeBuilderMixin { } /// Invokes `const` on this type with a [name]d constructor. - NewInstanceBuilder constInstanceWith( + NewInstanceBuilder namedConstInstance( String name, Iterable positional, [ Map named = const {}, @@ -50,7 +50,7 @@ abstract class AbstractTypeBuilderMixin { } /// Invokes `new` on this type with a [name]d constructor. - NewInstanceBuilder newInstanceWith( + NewInstanceBuilder namedNewInstance( String name, Iterable positional, [ Map named = const {}, diff --git a/lib/src/builders/type/new_instance.dart b/lib/src/builders/type/new_instance.dart index 66ceac3..c2d9b68 100644 --- a/lib/src/builders/type/new_instance.dart +++ b/lib/src/builders/type/new_instance.dart @@ -4,9 +4,9 @@ part of code_builder.src.builders.type; /// /// See [TypeBuilder]: /// - [TypeBuilder.constInstance] -/// - [TypeBuilder.constInstanceWith] +/// - [TypeBuilder.namedConstInstance] /// - [TypeBuilder.newInstance] -/// - [TypeBuilder.newInstanceWith] +/// - [TypeBuilder.namedNewInstance] abstract class NewInstanceBuilder implements AnnotationBuilder, InvocationBuilder { factory NewInstanceBuilder._const(TypeBuilder type, [String name]) { diff --git a/lib/src/pretty_printer.dart b/lib/src/pretty_printer.dart index 9bb1d08..53d3324 100644 --- a/lib/src/pretty_printer.dart +++ b/lib/src/pretty_printer.dart @@ -4,11 +4,21 @@ import 'package:analyzer/analyzer.dart'; import 'package:analyzer/dart/ast/token.dart'; -import 'package:code_builder/code_builder.dart'; import 'package:dart_style/dart_style.dart'; import 'analyzer_patch.dart'; +final _dartFmt = new DartFormatter(); + +/// Returns [source] formatted by `dartfmt`. +String dartfmt(String source) { + try { + return _dartFmt.format(source); + } on FormatterException catch (_) { + return _dartFmt.formatStatement(source); + } +} + /// Augments [AstNode.toSource] by adding some whitespace/line breaks. /// /// The final result is run through `dartfmt`. diff --git a/lib/src/scope.dart b/lib/src/scope.dart index dd81a8e..f6f6ec4 100644 --- a/lib/src/scope.dart +++ b/lib/src/scope.dart @@ -30,10 +30,10 @@ Identifier identifier(Scope scope, String name, [String importFrom]) { /// print(scope.identifier('Foo', 'package:foo/foo.dart')); /// /// // May print 'i1.Bar'. -/// print(scope.identifier('Bar'), 'package:foo/foo.dart'); +/// print(scope.identifier('Bar', 'package:foo/foo.dart')); /// /// // May print 'i2.Bar'. -/// print(scope.getIdentifier('Baz'), 'package:bar/bar.dart'); +/// print(scope.getIdentifier('Baz', 'package:bar/bar.dart')); /// } abstract class Scope { /// A no-op [Scope]. Ideal for use for tests or example cases. @@ -45,8 +45,8 @@ abstract class Scope { /// Create a new scoping context. /// - /// Actual implementation of is _not_ guaranteed, only that all import - /// prefixes will be unique in a given scope. + /// Actual implementation of [Scope] is _not_ guaranteed, only that all + /// import prefixes will be unique in a given scope. factory Scope() = _IncrementingScope; /// Create a context that just collects and de-duplicates imports. diff --git a/lib/testing.dart b/lib/testing.dart index 2437a97..ef6ae98 100644 --- a/lib/testing.dart +++ b/lib/testing.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:code_builder/code_builder.dart'; +import 'package:code_builder/src/pretty_printer.dart'; import 'package:dart_style/dart_style.dart'; import 'package:matcher/matcher.dart'; diff --git a/test/builders/class_test.dart b/test/builders/class_test.dart index 07e205a..40fe307 100644 --- a/test/builders/class_test.dart +++ b/test/builders/class_test.dart @@ -85,7 +85,7 @@ void main() { expect( clazz('Animal', [ constructor([ - parameter('name', [core.String]), + parameter('name', [lib$core.String]), thisField( named( parameter('age').asOptional(literal(0)), @@ -105,17 +105,17 @@ void main() { expect( clazz('Animal', [ asStatic( - varField('static1', type: core.String, value: literal('Hello')), + varField('static1', type: lib$core.String, value: literal('Hello')), ), asStatic( - varFinal('static2', type: core.List, value: literal([])), + varFinal('static2', type: lib$core.List, value: literal([])), ), asStatic( - varConst('static3', type: core.bool, value: literal(true)), + varConst('static3', type: lib$core.bool, value: literal(true)), ), - varField('var1', type: core.String, value: literal('Hello')), - varFinal('var2', type: core.List, value: literal([])), - varConst('var3', type: core.bool, value: literal(true)), + varField('var1', type: lib$core.String, value: literal('Hello')), + varFinal('var2', type: lib$core.List, value: literal([])), + varConst('var3', type: lib$core.bool, value: literal(true)), ]), equalsSource(r''' class Animal { @@ -134,15 +134,15 @@ void main() { expect( clazz('Animal', [ asStatic(method('staticMethod', [ - core.$void, - core.print.call([literal('Called staticMethod')]), + lib$core.$void, + lib$core.print.call([literal('Called staticMethod')]), ])), method('instanceMethod', [ - core.$void, - core.print.call([literal('Called instanceMethod')]), + lib$core.$void, + lib$core.print.call([literal('Called instanceMethod')]), ]), constructor([ - core.print.call([literal('Called constructor')]), + lib$core.print.call([literal('Called constructor')]), ]), ]), equalsSource(r''' diff --git a/test/builders/expression_test.dart b/test/builders/expression_test.dart index ad054c8..c00265b 100644 --- a/test/builders/expression_test.dart +++ b/test/builders/expression_test.dart @@ -89,7 +89,7 @@ void main() { test('should emit a typed assignemnt statement', () { expect( - literal(true).asVar('flag', core.bool), + literal(true).asVar('flag', lib$core.bool), equalsSource(r''' bool flag = true; '''), @@ -116,7 +116,7 @@ void main() { test('should call an expression as a function', () { expect( - core.identical.call([literal(true), literal(true)]), + lib$core.identical.call([literal(true), literal(true)]), equalsSource(r''' identical(true, true) '''), diff --git a/test/builders/field_test.dart b/test/builders/field_test.dart index 38511d0..fcadb66 100644 --- a/test/builders/field_test.dart +++ b/test/builders/field_test.dart @@ -6,7 +6,7 @@ import 'package:test/test.dart'; void main() { test('emit a var', () { expect( - varField('a', type: core.String, value: literal('Hello')), + varField('a', type: lib$core.String, value: literal('Hello')), equalsSource(r''' String a = 'Hello'; '''), @@ -15,7 +15,7 @@ void main() { test('emit a final', () { expect( - varFinal('a', type: core.String, value: literal('Hello')), + varFinal('a', type: lib$core.String, value: literal('Hello')), equalsSource(r''' final String a = 'Hello'; '''), @@ -24,7 +24,7 @@ void main() { test('emit a const', () { expect( - varConst('a', type: core.String, value: literal('Hello')), + varConst('a', type: lib$core.String, value: literal('Hello')), equalsSource(r''' const String a = 'Hello'; '''), diff --git a/test/builders/method_test.dart b/test/builders/method_test.dart index 6b12ec8..e532e62 100644 --- a/test/builders/method_test.dart +++ b/test/builders/method_test.dart @@ -20,7 +20,7 @@ void main() { test('should emit a top-level void main() function', () { expect( method('main', [ - core.$void, + lib$core.$void, ]).buildMethod(false).toSource(), equalsIgnoringWhitespace(r''' void main(); @@ -31,7 +31,7 @@ void main() { test('should emit a function with a parameter', () { expect( method('main', [ - parameter('args', [core.List]), + parameter('args', [lib$core.List]), ]).buildMethod(false).toSource(), equalsIgnoringWhitespace(r''' main(List args); @@ -123,7 +123,7 @@ void main() { test('should a method with a lambda value', () { expect( - lambda('supported', literal(true), returnType: core.bool), + lambda('supported', literal(true), returnType: lib$core.bool), equalsSource(r''' bool supported() => true; '''), @@ -144,7 +144,7 @@ void main() { expect( getter( 'values', - returnType: core.Iterable, + returnType: lib$core.Iterable, statements: [ literal([]).asReturn(), ], @@ -159,7 +159,7 @@ void main() { test('should emit a setter', () { expect( - setter('name', parameter('name', [core.String]), [ + setter('name', parameter('name', [lib$core.String]), [ (reference('name') + literal('!')).asAssign('_name'), ]), equalsSource(r''' diff --git a/test/builders/statement_test.dart b/test/builders/statement_test.dart index f6a0eb4..b899c85 100644 --- a/test/builders/statement_test.dart +++ b/test/builders/statement_test.dart @@ -8,7 +8,7 @@ void main() { test('should emit a simple if statement', () { expect( ifThen(literal(true), [ - core.print.call([literal('Hello World')]), + lib$core.print.call([literal('Hello World')]), ]), equalsSource(r''' if (true) { @@ -21,9 +21,9 @@ void main() { test('should emit an if then else statement', () { expect( ifThen(literal(true), [ - core.print.call([literal('TRUE')]), + lib$core.print.call([literal('TRUE')]), elseThen([ - core.print.call([literal('FALSE')]), + lib$core.print.call([literal('FALSE')]), ]), ]), equalsSource(r''' @@ -40,9 +40,9 @@ void main() { final a = reference('a'); expect( ifThen(a.equals(literal(1)), [ - core.print.call([literal('Was 1')]), + lib$core.print.call([literal('Was 1')]), elseIf(ifThen(a.equals(literal(2)), [ - core.print.call([literal('Was 2')]), + lib$core.print.call([literal('Was 2')]), ])), ]), equalsSource(r''' @@ -61,11 +61,11 @@ void main() { ifThen( a.equals(literal(1)), [ - core.print.call([literal('Was 1')]), + lib$core.print.call([literal('Was 1')]), elseIf(ifThen(a.equals(literal(2)), [ - core.print.call([literal('Was 2')]), + lib$core.print.call([literal('Was 2')]), elseThen([ - core.print.call([literal('Was ') + a]), + lib$core.print.call([literal('Was ') + a]), ]), ])), ], diff --git a/test/builders/type_test.dart b/test/builders/type_test.dart index f2eaa56..b9ac7b8 100644 --- a/test/builders/type_test.dart +++ b/test/builders/type_test.dart @@ -7,7 +7,7 @@ void main() { group('new instance', () { test('emits a new List', () { expect( - core.List.newInstance([]), + lib$core.List.newInstance([]), equalsSource(r''' new List() '''), @@ -16,7 +16,7 @@ void main() { test('emits a new List.from', () { expect( - core.List.newInstanceWith('from', [ + lib$core.List.namedNewInstance('from', [ literal([1, 2, 3]), ]), equalsSource(r''' @@ -40,7 +40,8 @@ void main() { test('emits a const constructor as an annotation', () { expect( clazz('Animal', [ - core.Deprecated.constInstance([literal('Animals are out of style')]), + lib$core.Deprecated + .constInstance([literal('Animals are out of style')]), ]), equalsSource(r''' @Deprecated('Animals are out of style') @@ -52,7 +53,7 @@ void main() { test('emits a named const constructor as an annotation', () { expect( clazz('Animal', [ - reference('Component').constInstanceWith( + reference('Component').namedConstInstance( 'stateful', [], { diff --git a/test/e2e_test.dart b/test/e2e_test.dart index 05a5475..1c88780 100644 --- a/test/e2e_test.dart +++ b/test/e2e_test.dart @@ -32,7 +32,7 @@ void main() { reference('_module').invoke('getDep2', []), ]), returnType: thingRef, - )..addAnnotation(core.override)); + )..addAnnotation(lib$core.override)); var lib = new LibraryBuilder() ..addDirective( new ImportBuilder('app.dart'), @@ -84,7 +84,7 @@ void main() { reference('_module').invoke('getDep1', []), reference('_module').invoke('getDep2', []), ]), - )..addAnnotation(core.override))); + )..addAnnotation(lib$core.override))); expect( lib, equalsSource( diff --git a/tool/presubmit.sh b/tool/presubmit.sh new file mode 100755 index 0000000..035e29e --- /dev/null +++ b/tool/presubmit.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Make sure dartfmt is run on everything +# This assumes you have dart_style as a dev_dependency +echo "Checking dartfmt..." +NEEDS_DARTFMT="$(find lib test -name "*.dart" | xargs pub run dart_style:format -n)" +if [[ ${NEEDS_DARTFMT} != "" ]] +then + echo "FAILED" + echo "${NEEDS_DARTFMT}" + exit 1 +fi +echo "PASSED" + +# Make sure we pass the analyzer +echo "Checking dartanalyzer..." +FAILS_ANALYZER="$(find lib test -name "*.dart" | xargs dartanalyzer --options analysis_options.yaml)" +if [[ $FAILS_ANALYZER == *"[error]"* ]] +then + echo "FAILED" + echo "${FAILS_ANALYZER}" + exit 1 +fi +echo "PASSED" + +# Fail on anything that fails going forward. +set -e + +pub run test