Chromium Code Reviews| 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_experimental/analyzer.dart'; | 9 import 'package:analyzer_experimental/analyzer.dart'; |
| 10 import 'package:analyzer_experimental/src/generated/parser.dart'; | 10 import 'package:analyzer_experimental/src/generated/parser.dart'; |
| (...skipping 1276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1287 //Handle EOLs before newlines | 1287 //Handle EOLs before newlines |
| 1288 if (isAtEOL(comment)) { | 1288 if (isAtEOL(comment)) { |
| 1289 emitComment(comment, previousToken); | 1289 emitComment(comment, previousToken); |
| 1290 comment = comment.next; | 1290 comment = comment.next; |
| 1291 currentToken = comment != null ? comment : token; | 1291 currentToken = comment != null ? comment : token; |
| 1292 } | 1292 } |
| 1293 | 1293 |
| 1294 var lines = max(min, countNewlinesBetween(previousToken, currentToken)); | 1294 var lines = max(min, countNewlinesBetween(previousToken, currentToken)); |
| 1295 writer.newlines(lines); | 1295 writer.newlines(lines); |
| 1296 | 1296 |
| 1297 var previousToken = currentToken.previous; | 1297 var newPreviousToken = currentToken.previous; |
| 1298 | 1298 |
| 1299 while (comment != null) { | 1299 while (comment != null) { |
| 1300 | 1300 |
| 1301 emitComment(comment, previousToken); | 1301 emitComment(comment, newPreviousToken); |
| 1302 | 1302 |
| 1303 var nextToken = comment.next != null ? comment.next : token; | 1303 var nextToken = comment.next != null ? comment.next : token; |
| 1304 var newlines = calculateNewlinesBetweenComments(comment, nextToken); | 1304 var newlines = calculateNewlinesBetweenComments(comment, nextToken); |
| 1305 if (newlines > 0) { | 1305 if (newlines > 0) { |
| 1306 writer.newlines(newlines); | 1306 writer.newlines(newlines); |
| 1307 lines += newlines; | 1307 lines += newlines; |
| 1308 } else if (!isEOF(token)) { | 1308 } else if (!isEOF(token)) { |
| 1309 space(); | 1309 space(); |
| 1310 } | 1310 } |
| 1311 | 1311 |
| 1312 previousToken = comment; | 1312 newPreviousToken = comment; |
| 1313 comment = comment.next; | 1313 comment = comment.next; |
| 1314 } | 1314 } |
| 1315 | 1315 |
| 1316 previousToken = token; | 1316 newPreviousToken = token; |
|
karlklose
2013/09/26 07:05:43
@pquitslund: This looks like a bug.
ngeoffray
2013/09/26 07:48:38
Why did you have to fix it? Isn't it OK to shadow
pquitslund
2013/09/30 16:12:48
Hmmm, I agree this doesn't look right. I have ano
pquitslund
2013/09/30 17:23:34
And here's that fix: https://codereview.chromium.o
| |
| 1317 return lines; | 1317 return lines; |
| 1318 } | 1318 } |
| 1319 | 1319 |
| 1320 | 1320 |
| 1321 ensureTrailingNewline() { | 1321 ensureTrailingNewline() { |
| 1322 if (writer.lastToken is! NewlineToken) { | 1322 if (writer.lastToken is! NewlineToken) { |
| 1323 writer.newline(); | 1323 writer.newline(); |
| 1324 } | 1324 } |
| 1325 } | 1325 } |
| 1326 | 1326 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1407 var lastLine = | 1407 var lastLine = |
| 1408 lineInfo.getLocation(lastOffset).lineNumber; | 1408 lineInfo.getLocation(lastOffset).lineNumber; |
| 1409 var currentLine = | 1409 var currentLine = |
| 1410 lineInfo.getLocation(currentOffset).lineNumber; | 1410 lineInfo.getLocation(currentOffset).lineNumber; |
| 1411 return currentLine - lastLine; | 1411 return currentLine - lastLine; |
| 1412 } | 1412 } |
| 1413 | 1413 |
| 1414 String toString() => writer.toString(); | 1414 String toString() => writer.toString(); |
| 1415 | 1415 |
| 1416 } | 1416 } |
| OLD | NEW |