Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(463)

Side by Side Diff: pkg/barback/lib/src/transformer/declaring_transform.dart

Issue 262173009: Add aggregate transformer types to barback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library barback.transformer.declaring_transform; 5 library barback.transformer.declaring_transform;
6 6
7 import 'dart:async';
8
7 import '../asset/asset_id.dart'; 9 import '../asset/asset_id.dart';
8 import '../graph/transform_node.dart'; 10 import 'declaring_aggregate_transform.dart';
9 import 'base_transform.dart'; 11 import 'transform_logger.dart';
10 12
11 /// A transform for [DeclaringTransform]ers that allows them to declare the ids 13 /// Creates a new [DeclaringTransform] wrapping an
14 /// [AggregateDeclaringTransform].
15 Future<DeclaringTransform> newDeclaringTransform(
16 DeclaringAggregateTransform aggregate) {
17 return aggregate.primaryIds.first.then((primaryId) =>
18 new DeclaringTransform._(aggregate, primaryId));
19 }
20
21 /// A transform for [DeclaringTransformer]s that allows them to declare the ids
12 /// of the outputs they'll generate without generating the concrete bodies of 22 /// of the outputs they'll generate without generating the concrete bodies of
13 /// those outputs. 23 /// those outputs.
14 class DeclaringTransform extends BaseTransform { 24 class DeclaringTransform {
15 final _outputIds = new Set<AssetId>(); 25 final DeclaringAggregateTransform _aggregate;
16 26
17 final AssetId primaryId; 27 final AssetId primaryId;
18 28
19 DeclaringTransform._(TransformNode node) 29 /// A logger so that the [Transformer] can report build details.
20 : primaryId = node.primary.id, 30 TransformLogger get logger => _aggregate.logger;
21 super(node); 31
32 DeclaringTransform._(this._aggregate, this.primaryId);
22 33
23 /// Stores [id] as the id of an output that will be created by this 34 /// Stores [id] as the id of an output that will be created by this
24 /// transformation when it's run. 35 /// transformation when it's run.
25 /// 36 ///
26 /// A transformation can declare as many assets as it wants. If 37 /// A transformation can declare as many assets as it wants. If
27 /// [DeclaringTransformer.declareOutputs] declareds a given asset id for a 38 /// [DeclaringTransformer.declareOutputs] declareds a given asset id for a
28 /// given input, [Transformer.apply] should emit the corresponding asset as 39 /// given input, [Transformer.apply] should emit the corresponding asset as
29 /// well. 40 /// well.
30 void declareOutput(AssetId id) { 41 void declareOutput(AssetId id) => _aggregate.declareOutput(id);
31 // TODO(nweiz): This should immediately throw if an output with that ID 42
32 // has already been declared by this transformer. 43 /// Consume the primary input so that it doesn't get processed by future
33 _outputIds.add(id); 44 /// phases or emitted once processing has finished.
34 } 45 ///
46 /// Normally the primary input will automatically be forwarded unless the
47 /// transformer overwrites it by emitting an input with the same id. This
48 /// allows the transformer to tell barback not to forward the primary input
49 /// even if it's not overwritten.
50 void consumePrimary() => _aggregate.consumePrimary(primaryId);
35 } 51 }
36
37 /// The controller for [DeclaringTransform].
38 class DeclaringTransformController extends BaseTransformController {
39 DeclaringTransform get transform => super.transform;
40
41 /// The set of ids that the transformer declares it will emit for the given
42 /// primary input.
43 Set<AssetId> get outputIds => transform._outputIds;
44
45 DeclaringTransformController(TransformNode node)
46 : super(new DeclaringTransform._(node));
47 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698