| 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'; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 void close() { | 37 void close() { |
| 38 sinks.forEach((OutputSink sink) => sink.close()); | 38 sinks.forEach((OutputSink sink) => sink.close()); |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 | 41 |
| 42 class OutputCollector implements CompilerOutput { | 42 class OutputCollector implements CompilerOutput { |
| 43 Map<OutputType, Map<String, BufferedOutputSink>> outputMap = {}; | 43 Map<OutputType, Map<String, BufferedOutputSink>> outputMap = {}; |
| 44 | 44 |
| 45 String getOutput(String name, OutputType type) { | 45 String getOutput(String name, OutputType type) { |
| 46 Map<String, BufferedOutputSink> sinkMap = outputMap[type]; | 46 Map<String, BufferedOutputSink> sinkMap = outputMap[type]; |
| 47 if (sinkMap == null) return null; | 47 if (sinkMap == null) { |
| 48 print("No output available for $type."); |
| 49 return null; |
| 50 } |
| 48 BufferedOutputSink sink = sinkMap[name]; | 51 BufferedOutputSink sink = sinkMap[name]; |
| 49 return sink != null ? sink.text : null; | 52 if (sink == null) { |
| 53 print("Output '$name' not found for $type. Available: ${sinkMap.keys}"); |
| 54 return null; |
| 55 } else { |
| 56 return sink.text; |
| 57 } |
| 50 } | 58 } |
| 51 | 59 |
| 52 /// `true` if any output has been collected. | 60 /// `true` if any output has been collected. |
| 53 bool get hasOutput => !outputMap.isEmpty; | 61 bool get hasOutput => !outputMap.isEmpty; |
| 54 | 62 |
| 55 /// `true` if any output other than main output has been collected. | 63 /// `true` if any output other than main output has been collected. |
| 56 bool get hasExtraOutput { | 64 bool get hasExtraOutput { |
| 57 for (OutputType type in outputMap.keys) { | 65 for (OutputType type in outputMap.keys) { |
| 58 for (String name in outputMap[type].keys) { | 66 for (String name in outputMap[type].keys) { |
| 59 if (name != '') return true; | 67 if (name != '') return true; |
| 60 } | 68 } |
| 61 } | 69 } |
| 62 return false; | 70 return false; |
| 63 } | 71 } |
| 64 | 72 |
| 65 @override | 73 @override |
| 66 OutputSink createOutputSink(String name, String extension, OutputType type) { | 74 OutputSink createOutputSink(String name, String extension, OutputType type) { |
| 67 Map<String, BufferedOutputSink> sinkMap = | 75 Map<String, BufferedOutputSink> sinkMap = |
| 68 outputMap.putIfAbsent(type, () => {}); | 76 outputMap.putIfAbsent(type, () => {}); |
| 69 return sinkMap.putIfAbsent(name, () => new BufferedOutputSink()); | 77 return sinkMap.putIfAbsent(name, () => new BufferedOutputSink()); |
| 70 } | 78 } |
| 71 } | 79 } |
| OLD | NEW |