| 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 library formatter_impl; | 5 library formatter_impl; |
| 6 | 6 |
| 7 import 'dart:math'; | 7 import 'dart:math'; |
| 8 | 8 |
| 9 import 'package:analyzer/analyzer.dart'; | 9 import 'package:analyzer/analyzer.dart'; |
| 10 import 'package:analyzer/src/generated/java_core.dart' show CharSequence; | 10 import 'package:analyzer/src/generated/java_core.dart' show CharSequence; |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 int leadingSpaces = 0; | 360 int leadingSpaces = 0; |
| 361 | 361 |
| 362 /// A flag to specify whether line-leading spaces should be preserved (and | 362 /// A flag to specify whether line-leading spaces should be preserved (and |
| 363 /// addded to the indent level). | 363 /// addded to the indent level). |
| 364 bool allowLineLeadingSpaces; | 364 bool allowLineLeadingSpaces; |
| 365 | 365 |
| 366 /// Used for matching EOL comments | 366 /// Used for matching EOL comments |
| 367 final twoSlashes = new RegExp(r'//[^/]'); | 367 final twoSlashes = new RegExp(r'//[^/]'); |
| 368 | 368 |
| 369 /// A weight for potential breakpoints. | 369 /// A weight for potential breakpoints. |
| 370 int breakWeight = null; | 370 int breakWeight = DEFAULT_SPACE_WEIGHT; |
| 371 | 371 |
| 372 /// Original pre-format selection information (may be null). | 372 /// Original pre-format selection information (may be null). |
| 373 final Selection preSelection; | 373 final Selection preSelection; |
| 374 | 374 |
| 375 final bool codeTransforms; | 375 final bool codeTransforms; |
| 376 | 376 |
| 377 /// Post format selection information. | 377 /// Post format selection information. |
| 378 Selection selection; | 378 Selection selection; |
| 379 | 379 |
| 380 | 380 |
| (...skipping 1076 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1457 } | 1457 } |
| 1458 } | 1458 } |
| 1459 | 1459 |
| 1460 emitSpaces() { | 1460 emitSpaces() { |
| 1461 if (leadingSpaces > 0) { | 1461 if (leadingSpaces > 0) { |
| 1462 if (allowLineLeadingSpaces || !writer.currentLine.isWhitespace()) { | 1462 if (allowLineLeadingSpaces || !writer.currentLine.isWhitespace()) { |
| 1463 writer.spaces(leadingSpaces, breakWeight: breakWeight); | 1463 writer.spaces(leadingSpaces, breakWeight: breakWeight); |
| 1464 } | 1464 } |
| 1465 leadingSpaces = 0; | 1465 leadingSpaces = 0; |
| 1466 allowLineLeadingSpaces = false; | 1466 allowLineLeadingSpaces = false; |
| 1467 breakWeight = null; | 1467 breakWeight = DEFAULT_SPACE_WEIGHT; |
| 1468 } | 1468 } |
| 1469 } | 1469 } |
| 1470 | 1470 |
| 1471 checkForSelectionUpdate(Token token) { | 1471 checkForSelectionUpdate(Token token) { |
| 1472 // Cache the first token on or AFTER the selection offset | 1472 // Cache the first token on or AFTER the selection offset |
| 1473 if (preSelection != null && selection == null) { | 1473 if (preSelection != null && selection == null) { |
| 1474 // Check for overshots | 1474 // Check for overshots |
| 1475 var overshot = token.offset - preSelection.offset; | 1475 var overshot = token.offset - preSelection.offset; |
| 1476 if (overshot >= 0) { | 1476 if (overshot >= 0) { |
| 1477 //TODO(pquitslund): update length (may need truncating) | 1477 //TODO(pquitslund): update length (may need truncating) |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1678 var lastLine = | 1678 var lastLine = |
| 1679 lineInfo.getLocation(lastOffset).lineNumber; | 1679 lineInfo.getLocation(lastOffset).lineNumber; |
| 1680 var currentLine = | 1680 var currentLine = |
| 1681 lineInfo.getLocation(currentOffset).lineNumber; | 1681 lineInfo.getLocation(currentOffset).lineNumber; |
| 1682 return currentLine - lastLine; | 1682 return currentLine - lastLine; |
| 1683 } | 1683 } |
| 1684 | 1684 |
| 1685 String toString() => writer.toString(); | 1685 String toString() => writer.toString(); |
| 1686 | 1686 |
| 1687 } | 1687 } |
| OLD | NEW |