| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 // Output provider that collects the output in string buffers. | 5 // Output provider that collects the output in string buffers. |
| 6 | 6 |
| 7 library output_collector; | 7 library output_collector; |
| 8 | 8 |
| 9 import 'dart:async'; | 9 import 'dart:async'; |
| 10 import 'package:compiler/compiler_new.dart'; | 10 import 'package:compiler/compiler_new.dart'; |
| 11 | 11 |
| 12 class BufferedOutputSink implements OutputSink { | 12 class BufferedOutputSink implements OutputSink { |
| 13 StringBuffer sb = new StringBuffer(); | 13 StringBuffer sb = new StringBuffer(); |
| 14 String text; | 14 String text; |
| 15 | 15 |
| 16 void add(String event) { | 16 void add(String event) { |
| 17 sb.write(event); | 17 sb.write(event); |
| 18 } | 18 } |
| 19 | 19 |
| 20 void close() { | 20 void close() { |
| 21 text = sb.toString(); | 21 text = sb.toString(); |
| 22 sb = null; | 22 sb = null; |
| 23 } | 23 } |
| 24 |
| 25 String toString() { |
| 26 return text ?? sb.toString(); |
| 27 } |
| 24 } | 28 } |
| 25 | 29 |
| 26 class CloningOutputSink implements OutputSink { | 30 class CloningOutputSink implements OutputSink { |
| 27 final List<OutputSink> sinks; | 31 final List<OutputSink> sinks; |
| 28 | 32 |
| 29 CloningOutputSink(this.sinks); | 33 CloningOutputSink(this.sinks); |
| 30 | 34 |
| 31 @override | 35 @override |
| 32 void add(String event) { | 36 void add(String event) { |
| 33 sinks.forEach((OutputSink sink) => sink.add(event)); | 37 sinks.forEach((OutputSink sink) => sink.add(event)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 return false; | 74 return false; |
| 71 } | 75 } |
| 72 | 76 |
| 73 @override | 77 @override |
| 74 OutputSink createOutputSink(String name, String extension, OutputType type) { | 78 OutputSink createOutputSink(String name, String extension, OutputType type) { |
| 75 Map<String, BufferedOutputSink> sinkMap = | 79 Map<String, BufferedOutputSink> sinkMap = |
| 76 outputMap.putIfAbsent(type, () => {}); | 80 outputMap.putIfAbsent(type, () => {}); |
| 77 return sinkMap.putIfAbsent(name, () => new BufferedOutputSink()); | 81 return sinkMap.putIfAbsent(name, () => new BufferedOutputSink()); |
| 78 } | 82 } |
| 79 } | 83 } |
| OLD | NEW |