| OLD | NEW |
| 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 dart_style.src.source_code; | 5 library dart_style.src.source_code; |
| 6 | 6 |
| 7 /// Describes a chunk of source code that is to be formatted or has been | 7 /// Describes a chunk of source code that is to be formatted or has been |
| 8 /// formatted. | 8 /// formatted. |
| 9 class SourceCode { | 9 class SourceCode { |
| 10 /// The [uri] where the source code is from. | 10 /// The [uri] where the source code is from. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 /// Gets the source code following the selection. | 44 /// Gets the source code following the selection. |
| 45 /// | 45 /// |
| 46 /// If there is no selection, returns an empty string. | 46 /// If there is no selection, returns an empty string. |
| 47 String get textAfterSelection { | 47 String get textAfterSelection { |
| 48 if (selectionStart == null) return ""; | 48 if (selectionStart == null) return ""; |
| 49 return text.substring(selectionStart + selectionLength); | 49 return text.substring(selectionStart + selectionLength); |
| 50 } | 50 } |
| 51 | 51 |
| 52 SourceCode(this.text, | 52 SourceCode(this.text, |
| 53 {this.uri, this.isCompilationUnit: true, this.selectionStart, | 53 {this.uri, |
| 54 this.isCompilationUnit: true, |
| 55 this.selectionStart, |
| 54 this.selectionLength}) { | 56 this.selectionLength}) { |
| 55 // Must either provide both selection bounds or neither. | 57 // Must either provide both selection bounds or neither. |
| 56 if ((selectionStart == null) != (selectionLength == null)) { | 58 if ((selectionStart == null) != (selectionLength == null)) { |
| 57 throw new ArgumentError( | 59 throw new ArgumentError( |
| 58 "Is selectionStart is provided, selectionLength must be too."); | 60 "Is selectionStart is provided, selectionLength must be too."); |
| 59 } | 61 } |
| 60 | 62 |
| 61 if (selectionStart != null) { | 63 if (selectionStart != null) { |
| 62 if (selectionStart < 0) { | 64 if (selectionStart < 0) { |
| 63 throw new ArgumentError("selectionStart must be non-negative."); | 65 throw new ArgumentError("selectionStart must be non-negative."); |
| 64 } | 66 } |
| 65 | 67 |
| 66 if (selectionStart > text.length) { | 68 if (selectionStart > text.length) { |
| 67 throw new ArgumentError("selectionStart must be within text."); | 69 throw new ArgumentError("selectionStart must be within text."); |
| 68 } | 70 } |
| 69 } | 71 } |
| 70 | 72 |
| 71 if (selectionLength != null) { | 73 if (selectionLength != null) { |
| 72 if (selectionLength < 0) { | 74 if (selectionLength < 0) { |
| 73 throw new ArgumentError("selectionLength must be non-negative."); | 75 throw new ArgumentError("selectionLength must be non-negative."); |
| 74 } | 76 } |
| 75 | 77 |
| 76 if (selectionStart + selectionLength > text.length) { | 78 if (selectionStart + selectionLength > text.length) { |
| 77 throw new ArgumentError("selectionLength must end within text."); | 79 throw new ArgumentError("selectionLength must end within text."); |
| 78 } | 80 } |
| 79 } | 81 } |
| 80 } | 82 } |
| 81 } | 83 } |
| OLD | NEW |