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.chunk; | 5 library dart_style.src.chunk; |
6 | 6 |
7 import 'debug.dart'; | 7 import 'debug.dart'; |
8 | 8 |
9 /// Tracks where a selection start or end point may appear in some piece of | 9 /// Tracks where a selection start or end point may appear in some piece of |
10 /// text. | 10 /// text. |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 /// most desirable. | 223 /// most desirable. |
224 class Cost { | 224 class Cost { |
225 /// The smallest cost. | 225 /// The smallest cost. |
226 /// | 226 /// |
227 /// This isn't zero because we want to ensure all splitting has *some* cost, | 227 /// This isn't zero because we want to ensure all splitting has *some* cost, |
228 /// otherwise, the formatter won't try to keep things on one line at all. | 228 /// otherwise, the formatter won't try to keep things on one line at all. |
229 /// Almost all splits and spans use this. Greater costs tend to come from a | 229 /// Almost all splits and spans use this. Greater costs tend to come from a |
230 /// greater number of nested spans. | 230 /// greater number of nested spans. |
231 static const normal = 1; | 231 static const normal = 1; |
232 | 232 |
233 /// The cost of splitting after a "=" both for assignment and initialization. | 233 /// Splitting after a "=" both for assignment and initialization. |
234 static const assignment = 2; | 234 static const assignment = 2; |
235 | 235 |
| 236 /// Splitting before the first argument when it happens to be a function |
| 237 /// expression with a block body. |
| 238 static const firstBlockArgument = 2; |
| 239 |
| 240 /// The series of positional arguments. |
| 241 static const positionalArguments = 2; |
| 242 |
| 243 /// Splitting inside the brackets of a list with only one element. |
| 244 static const singleElementList = 2; |
| 245 |
236 /// The cost of a single character that goes past the page limit. | 246 /// The cost of a single character that goes past the page limit. |
237 /// | 247 /// |
238 /// This cost is high to ensure any solution that fits in the page is | 248 /// This cost is high to ensure any solution that fits in the page is |
239 /// preferred over one that does not. | 249 /// preferred over one that does not. |
240 static const overflowChar = 1000; | 250 static const overflowChar = 1000; |
241 } | 251 } |
242 | 252 |
243 /// Controls whether or not one or more soft split [Chunk]s are split. | 253 /// Controls whether or not one or more soft split [Chunk]s are split. |
244 /// | 254 /// |
245 /// When [LineSplitter] tries to split a line to fit within its page width, it | 255 /// When [LineSplitter] tries to split a line to fit within its page width, it |
(...skipping 14 matching lines...) Expand all Loading... |
260 final int cost; | 270 final int cost; |
261 | 271 |
262 /// The other [SplitParam]s that are "implied" by this one. | 272 /// The other [SplitParam]s that are "implied" by this one. |
263 /// | 273 /// |
264 /// Implication means that if the splitter chooses to split this param, it | 274 /// Implication means that if the splitter chooses to split this param, it |
265 /// must also split all of its implied ones (transitively). Implication is | 275 /// must also split all of its implied ones (transitively). Implication is |
266 /// one-way. If A implies B, it's fine to split B without splitting A. | 276 /// one-way. If A implies B, it's fine to split B without splitting A. |
267 final implies = <SplitParam>[]; | 277 final implies = <SplitParam>[]; |
268 | 278 |
269 /// Creates a new [SplitParam]. | 279 /// Creates a new [SplitParam]. |
270 SplitParam([this.cost = Cost.normal]); | 280 SplitParam([int cost]) |
| 281 : cost = cost != null ? cost : Cost.normal; |
271 | 282 |
272 String toString() => "$id"; | 283 String toString() => "$id"; |
273 | 284 |
274 int get hashCode => id.hashCode; | 285 int get hashCode => id.hashCode; |
275 | 286 |
276 bool operator ==(other) => identical(this, other); | 287 bool operator ==(other) => identical(this, other); |
277 } | 288 } |
278 | 289 |
279 /// Delimits a range of chunks that must end up on the same line to avoid an | 290 /// Delimits a range of chunks that must end up on the same line to avoid an |
280 /// additional cost. | 291 /// additional cost. |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 /// Whether this comment starts at column one in the source. | 363 /// Whether this comment starts at column one in the source. |
353 /// | 364 /// |
354 /// Comments that start at the start of the line will not be indented in the | 365 /// Comments that start at the start of the line will not be indented in the |
355 /// output. This way, commented out chunks of code do not get erroneously | 366 /// output. This way, commented out chunks of code do not get erroneously |
356 /// re-indented. | 367 /// re-indented. |
357 final bool isStartOfLine; | 368 final bool isStartOfLine; |
358 | 369 |
359 SourceComment(this.text, this.linesBefore, | 370 SourceComment(this.text, this.linesBefore, |
360 {this.isLineComment, this.isStartOfLine}); | 371 {this.isLineComment, this.isStartOfLine}); |
361 } | 372 } |
OLD | NEW |