From c5824711f68116c90184a43f3187911dc9162745 Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Thu, 30 Mar 2017 17:16:54 -0700 Subject: [PATCH] Expose Uri for some builders. (dart-lang/code_builder#104) --- pkgs/code_builder/lib/code_builder.dart | 3 +- pkgs/code_builder/lib/src/builders/file.dart | 32 ++++++++++++-------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/pkgs/code_builder/lib/code_builder.dart b/pkgs/code_builder/lib/code_builder.dart index d049656d0..8fd41c75b 100644 --- a/pkgs/code_builder/lib/code_builder.dart +++ b/pkgs/code_builder/lib/code_builder.dart @@ -15,7 +15,8 @@ export 'src/builders/file.dart' ImportBuilder, LibraryBuilder, PartBuilder, - PartOfBuilder; + PartOfBuilder, + UriDirectiveBuilder; export 'src/builders/method.dart' show constructor, diff --git a/pkgs/code_builder/lib/src/builders/file.dart b/pkgs/code_builder/lib/src/builders/file.dart index 52b52a530..915dc64ef 100644 --- a/pkgs/code_builder/lib/src/builders/file.dart +++ b/pkgs/code_builder/lib/src/builders/file.dart @@ -144,14 +144,20 @@ class _LibraryDirectiveBuilder implements AstBuilder { } } +/// A builder that has a reference to a [uri]. +abstract class UriDirectiveBuilder implements AstBuilder { + String get uri; +} + /// Lazily builds a [PartDirective] AST when built. class PartBuilder extends Object with HasAnnotationsMixin - implements AstBuilder { - final String _uri; + implements AstBuilder, UriDirectiveBuilder { + @override + final String uri; factory PartBuilder(String uri) = PartBuilder._; - PartBuilder._(this._uri); + PartBuilder._(this.uri); @override PartDirective buildAst([Scope scope]) { @@ -159,7 +165,7 @@ class PartBuilder extends Object null, buildAnnotations(scope), $part, - astFactory.simpleStringLiteral(stringToken("'$_uri'"), _uri), + astFactory.simpleStringLiteral(stringToken("'$uri'"), uri), $semicolon, ); } @@ -168,9 +174,10 @@ class PartBuilder extends Object /// Lazily builds an [ImportDirective] AST when built. class ImportBuilder extends Object with HasAnnotationsMixin - implements AstBuilder { + implements AstBuilder, UriDirectiveBuilder { final String _prefix; - final String _uri; + @override + final String uri; final bool _deferred; final Set _show = new Set(); @@ -180,7 +187,7 @@ class ImportBuilder extends Object return new ImportBuilder._(path, prefix, deferred); } - ImportBuilder._(this._uri, this._prefix, this._deferred); + ImportBuilder._(this.uri, this._prefix, this._deferred); void hide(String identifier) { _hide.add(identifier); @@ -221,7 +228,7 @@ class ImportBuilder extends Object null, buildAnnotations(scope), null, - astFactory.simpleStringLiteral(stringToken("'$_uri'"), _uri), + astFactory.simpleStringLiteral(stringToken("'$uri'"), uri), null, _deferred ? $deferred : null, _prefix != null ? $as : null, @@ -235,15 +242,16 @@ class ImportBuilder extends Object /// Lazily builds an [ExportDirective] AST when built. class ExportBuilder extends Object with HasAnnotationsMixin - implements AstBuilder { - final String _uri; + implements AstBuilder, UriDirectiveBuilder { + @override + final String uri; final Set _show = new Set(); final Set _hide = new Set(); factory ExportBuilder(String path) = ExportBuilder._; - ExportBuilder._(this._uri); + ExportBuilder._(this.uri); void hide(String identifier) { _hide.add(identifier); @@ -284,7 +292,7 @@ class ExportBuilder extends Object null, buildAnnotations(scope), null, - astFactory.simpleStringLiteral(stringToken("'$_uri'"), _uri), + astFactory.simpleStringLiteral(stringToken("'$uri'"), uri), null, combinators, $semicolon,