| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 dart2js.code_output; | 5 library dart2js.code_output; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import '../../compiler_new.dart'; |
| 8 | |
| 9 import 'source_information.dart'; | 8 import 'source_information.dart'; |
| 10 | 9 |
| 11 /// Listener interface for [CodeOutput] activity. | 10 /// Listener interface for [CodeOutput] activity. |
| 12 abstract class CodeOutputListener { | 11 abstract class CodeOutputListener { |
| 13 /// Called when [text] is added to the output. | 12 /// Called when [text] is added to the output. |
| 14 void onText(String text); | 13 void onText(String text); |
| 15 | 14 |
| 16 /// Called when the output is closed with a final length of [length]. | 15 /// Called when the output is closed with a final length of [length]. |
| 17 void onDone(int length); | 16 void onDone(int length); |
| 18 } | 17 } |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 } | 122 } |
| 124 | 123 |
| 125 String toString() { | 124 String toString() { |
| 126 throw "Don't use CodeBuffer.toString() since it drops sourcemap data."; | 125 throw "Don't use CodeBuffer.toString() since it drops sourcemap data."; |
| 127 } | 126 } |
| 128 } | 127 } |
| 129 | 128 |
| 130 /// [CodeOutput] using a [CompilationOutput] as backend. | 129 /// [CodeOutput] using a [CompilationOutput] as backend. |
| 131 class StreamCodeOutput extends AbstractCodeOutput { | 130 class StreamCodeOutput extends AbstractCodeOutput { |
| 132 int length = 0; | 131 int length = 0; |
| 133 final EventSink<String> output; | 132 final OutputSink output; |
| 134 final List<CodeOutputListener> _listeners; | 133 final List<CodeOutputListener> _listeners; |
| 135 | 134 |
| 136 StreamCodeOutput(this.output, [this._listeners]); | 135 StreamCodeOutput(this.output, [this._listeners]); |
| 137 | 136 |
| 138 @override | 137 @override |
| 139 void _addInternal(String text) { | 138 void _addInternal(String text) { |
| 140 output.add(text); | 139 output.add(text); |
| 141 length += text.length; | 140 length += text.length; |
| 142 if (_listeners != null) { | 141 if (_listeners != null) { |
| 143 _listeners.forEach((listener) => listener.onText(text)); | 142 _listeners.forEach((listener) => listener.onText(text)); |
| 144 } | 143 } |
| 145 } | 144 } |
| 146 | 145 |
| 147 void close() { | 146 void close() { |
| 148 output.close(); | 147 output.close(); |
| 149 super.close(); | 148 super.close(); |
| 150 if (_listeners != null) { | 149 if (_listeners != null) { |
| 151 _listeners.forEach((listener) => listener.onDone(length)); | 150 _listeners.forEach((listener) => listener.onDone(length)); |
| 152 } | 151 } |
| 153 } | 152 } |
| 154 } | 153 } |
| OLD | NEW |