| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /// Tools to help implement refactoring like transformations to Dart code. | 5 /// Tools to help implement refactoring like transformations to Dart code. |
| 6 /// | 6 /// |
| 7 /// [TextEditTransaction] supports making a series of changes to a text buffer. | 7 /// [TextEditTransaction] supports making a series of changes to a text buffer. |
| 8 /// [guessIndent] helps to guess the appropriate indentiation for the new code. | 8 /// [guessIndent] helps to guess the appropriate indentiation for the new code. |
| 9 library source_maps.refactor; | 9 library source_maps.refactor; |
| 10 | 10 |
| 11 import 'span.dart'; | 11 import 'span.dart'; |
| 12 import 'printer.dart'; | 12 import 'printer.dart'; |
| 13 import 'src/span_wrapper.dart'; |
| 13 | 14 |
| 14 /// Editable text transaction. | 15 /// Editable text transaction. |
| 15 /// | 16 /// |
| 16 /// Applies a series of edits using original location | 17 /// Applies a series of edits using original location |
| 17 /// information, and composes them into the edited string. | 18 /// information, and composes them into the edited string. |
| 18 class TextEditTransaction { | 19 class TextEditTransaction { |
| 19 final SourceFile file; | 20 final SourceFile file; |
| 20 final String original; | 21 final String original; |
| 21 final _edits = <_TextEdit>[]; | 22 final _edits = <_TextEdit>[]; |
| 22 | 23 |
| 23 TextEditTransaction(this.original, this.file); | 24 /// Creates a new transaction. |
| 25 /// |
| 26 /// [file] can be either a `source_map` [SourceFile] or a `source_span` |
| 27 /// `SourceFile`. Using a `source_map` [SourceFile] is deprecated and will be |
| 28 /// unsupported in version 0.10.0. |
| 29 TextEditTransaction(this.original, file) |
| 30 : file = SourceFileWrapper.wrap(file); |
| 24 | 31 |
| 25 bool get hasEdits => _edits.length > 0; | 32 bool get hasEdits => _edits.length > 0; |
| 26 | 33 |
| 27 /// Edit the original text, replacing text on the range [begin] and [end] | 34 /// Edit the original text, replacing text on the range [begin] and [end] |
| 28 /// with the [replacement]. [replacement] can be either a string or a | 35 /// with the [replacement]. [replacement] can be either a string or a |
| 29 /// [NestedPrinter]. | 36 /// [NestedPrinter]. |
| 30 void edit(int begin, int end, replacement) { | 37 void edit(int begin, int end, replacement) { |
| 31 _edits.add(new _TextEdit(begin, end, replacement)); | 38 _edits.add(new _TextEdit(begin, end, replacement)); |
| 32 } | 39 } |
| 33 | 40 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 } | 129 } |
| 123 } | 130 } |
| 124 | 131 |
| 125 return code.substring(lineStart, whitespaceEnd); | 132 return code.substring(lineStart, whitespaceEnd); |
| 126 } | 133 } |
| 127 | 134 |
| 128 const int _CR = 13; | 135 const int _CR = 13; |
| 129 const int _LF = 10; | 136 const int _LF = 10; |
| 130 const int _TAB = 9; | 137 const int _TAB = 9; |
| 131 const int _SPACE = 32; | 138 const int _SPACE = 32; |
| OLD | NEW |