Skip to content

Commit

Permalink
Expose Uri for some builders. (dart-archive/code_builder#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
matanlurey authored Mar 31, 2017
1 parent f98d82a commit c582471
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
3 changes: 2 additions & 1 deletion pkgs/code_builder/lib/code_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export 'src/builders/file.dart'
ImportBuilder,
LibraryBuilder,
PartBuilder,
PartOfBuilder;
PartOfBuilder,
UriDirectiveBuilder;
export 'src/builders/method.dart'
show
constructor,
Expand Down
32 changes: 20 additions & 12 deletions pkgs/code_builder/lib/src/builders/file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,28 @@ class _LibraryDirectiveBuilder implements AstBuilder<LibraryDirective> {
}
}

/// A builder that has a reference to a [uri].
abstract class UriDirectiveBuilder implements AstBuilder<Directive> {
String get uri;
}

/// Lazily builds a [PartDirective] AST when built.
class PartBuilder extends Object
with HasAnnotationsMixin
implements AstBuilder<PartDirective> {
final String _uri;
implements AstBuilder<PartDirective>, UriDirectiveBuilder {
@override
final String uri;

factory PartBuilder(String uri) = PartBuilder._;
PartBuilder._(this._uri);
PartBuilder._(this.uri);

@override
PartDirective buildAst([Scope scope]) {
return astFactory.partDirective(
null,
buildAnnotations(scope),
$part,
astFactory.simpleStringLiteral(stringToken("'$_uri'"), _uri),
astFactory.simpleStringLiteral(stringToken("'$uri'"), uri),
$semicolon,
);
}
Expand All @@ -168,9 +174,10 @@ class PartBuilder extends Object
/// Lazily builds an [ImportDirective] AST when built.
class ImportBuilder extends Object
with HasAnnotationsMixin
implements AstBuilder<ImportDirective> {
implements AstBuilder<ImportDirective>, UriDirectiveBuilder {
final String _prefix;
final String _uri;
@override
final String uri;
final bool _deferred;

final Set<String> _show = new Set<String>();
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -235,15 +242,16 @@ class ImportBuilder extends Object
/// Lazily builds an [ExportDirective] AST when built.
class ExportBuilder extends Object
with HasAnnotationsMixin
implements AstBuilder<ExportDirective> {
final String _uri;
implements AstBuilder<ExportDirective>, UriDirectiveBuilder {
@override
final String uri;

final Set<String> _show = new Set<String>();
final Set<String> _hide = new Set<String>();

factory ExportBuilder(String path) = ExportBuilder._;

ExportBuilder._(this._uri);
ExportBuilder._(this.uri);

void hide(String identifier) {
_hide.add(identifier);
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit c582471

Please sign in to comment.