| 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 1479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1490 int emitPrecedingCommentsAndNewlines(Token token, {min: 0}) { | 1490 int emitPrecedingCommentsAndNewlines(Token token, {min: 0}) { |
| 1491 | 1491 |
| 1492 var comment = token.precedingComments; | 1492 var comment = token.precedingComments; |
| 1493 var currentToken = comment != null ? comment : token; | 1493 var currentToken = comment != null ? comment : token; |
| 1494 | 1494 |
| 1495 //Handle EOLs before newlines | 1495 //Handle EOLs before newlines |
| 1496 if (isAtEOL(comment)) { | 1496 if (isAtEOL(comment)) { |
| 1497 emitComment(comment, previousToken); | 1497 emitComment(comment, previousToken); |
| 1498 comment = comment.next; | 1498 comment = comment.next; |
| 1499 currentToken = comment != null ? comment : token; | 1499 currentToken = comment != null ? comment : token; |
| 1500 // Ensure EOL comments force a linebreak |
| 1501 needsNewline = true; |
| 1500 } | 1502 } |
| 1501 | 1503 |
| 1502 var lines = 0; | 1504 var lines = 0; |
| 1503 if (needsNewline || preserveNewlines) { | 1505 if (needsNewline || preserveNewlines) { |
| 1504 lines = max(min, countNewlinesBetween(previousToken, currentToken)); | 1506 lines = max(min, countNewlinesBetween(previousToken, currentToken)); |
| 1505 preserveNewlines = false; | 1507 preserveNewlines = false; |
| 1506 } | 1508 } |
| 1507 emitNewlines(lines); | 1509 emitNewlines(lines); |
| 1508 | 1510 |
| 1509 previousToken = | 1511 previousToken = |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1626 var lastLine = | 1628 var lastLine = |
| 1627 lineInfo.getLocation(lastOffset).lineNumber; | 1629 lineInfo.getLocation(lastOffset).lineNumber; |
| 1628 var currentLine = | 1630 var currentLine = |
| 1629 lineInfo.getLocation(currentOffset).lineNumber; | 1631 lineInfo.getLocation(currentOffset).lineNumber; |
| 1630 return currentLine - lastLine; | 1632 return currentLine - lastLine; |
| 1631 } | 1633 } |
| 1632 | 1634 |
| 1633 String toString() => writer.toString(); | 1635 String toString() => writer.toString(); |
| 1634 | 1636 |
| 1635 } | 1637 } |
| OLD | NEW |