| 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.whitespace; | 5 library dart_style.src.whitespace; |
| 6 | 6 |
| 7 /// The kind of pending whitespace that has been "written", but not actually | 7 /// The kind of pending whitespace that has been "written", but not actually |
| 8 /// physically output yet. | 8 /// physically output yet. |
| 9 /// | 9 /// |
| 10 /// We defer actually writing whitespace until a non-whitespace token is | 10 /// We defer actually writing whitespace until a non-whitespace token is |
| 11 /// encountered to avoid trailing whitespace. | 11 /// encountered to avoid trailing whitespace. |
| 12 class Whitespace { | 12 class Whitespace { |
| 13 /// No whitespace. |
| 14 static const none = const Whitespace._("none"); |
| 15 |
| 13 /// A single non-breaking space. | 16 /// A single non-breaking space. |
| 14 static const space = const Whitespace._("space"); | 17 static const space = const Whitespace._("space"); |
| 15 | 18 |
| 16 /// A single newline. | 19 /// A single newline. |
| 17 static const newline = const Whitespace._("newline"); | 20 static const newline = const Whitespace._("newline"); |
| 18 | 21 |
| 19 /// A single newline that takes into account the current expression nesting | 22 /// A single newline that takes into account the current expression nesting |
| 20 /// for the next line. | 23 /// for the next line. |
| 21 static const nestedNewline = const Whitespace._("nestedNewline"); | 24 static const nestedNewline = const Whitespace._("nestedNewline"); |
| 22 | 25 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 38 | 41 |
| 39 /// One or two newlines should be output based on how many newlines are | 42 /// One or two newlines should be output based on how many newlines are |
| 40 /// present between the next token and the previous one. | 43 /// present between the next token and the previous one. |
| 41 /// | 44 /// |
| 42 /// In general, we like to avoid using this because it makes the formatter | 45 /// In general, we like to avoid using this because it makes the formatter |
| 43 /// less prescriptive over the user's whitespace. | 46 /// less prescriptive over the user's whitespace. |
| 44 static const oneOrTwoNewlines = const Whitespace._("oneOrTwoNewlines"); | 47 static const oneOrTwoNewlines = const Whitespace._("oneOrTwoNewlines"); |
| 45 | 48 |
| 46 final String name; | 49 final String name; |
| 47 | 50 |
| 51 /// Gets the minimum number of newlines contained in this whitespace. |
| 52 int get minimumLines { |
| 53 switch (this) { |
| 54 case Whitespace.newline: |
| 55 case Whitespace.nestedNewline: |
| 56 case Whitespace.newlineFlushLeft: |
| 57 case Whitespace.oneOrTwoNewlines: |
| 58 return 1; |
| 59 |
| 60 case Whitespace.twoNewlines: |
| 61 return 2; |
| 62 |
| 63 default: |
| 64 return 0; |
| 65 } |
| 66 } |
| 67 |
| 48 const Whitespace._(this.name); | 68 const Whitespace._(this.name); |
| 49 | 69 |
| 50 String toString() => name; | 70 String toString() => name; |
| 51 } | 71 } |
| OLD | NEW |