| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// Helper for creating HTML visualization of the source map information | 5 /// Helper for creating HTML visualization of the source map information |
| 6 /// generated by a [SourceMapProcessor]. | 6 /// generated by a [SourceMapProcessor]. |
| 7 | 7 |
| 8 library sourcemap.html.helper; | 8 library sourcemap.html.helper; |
| 9 | 9 |
| 10 import 'dart:convert'; | 10 import 'dart:convert'; |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 dartCodeBuffer.write('<h4>${uri.pathSegments.last}, ' | 508 dartCodeBuffer.write('<h4>${uri.pathSegments.last}, ' |
| 509 '${firstLineIndex - windowSize + 1}-' | 509 '${firstLineIndex - windowSize + 1}-' |
| 510 '${lastLineIndex + windowSize + 1}' | 510 '${lastLineIndex + windowSize + 1}' |
| 511 '</h4>\n'); | 511 '</h4>\n'); |
| 512 dartCodeBuffer.write('<pre>\n'); | 512 dartCodeBuffer.write('<pre>\n'); |
| 513 for (int line = firstLineIndex - windowSize; | 513 for (int line = firstLineIndex - windowSize; |
| 514 line < firstLineIndex; | 514 line < firstLineIndex; |
| 515 line++) { | 515 line++) { |
| 516 if (line >= 0) { | 516 if (line >= 0) { |
| 517 dartCodeBuffer.write(lineNumber(line, width: lineNoWidth)); | 517 dartCodeBuffer.write(lineNumber(line, width: lineNoWidth)); |
| 518 dartCodeBuffer.write(sourceFile.getLineText(line)); | 518 dartCodeBuffer.write(sourceFile.kernelSource.getTextLine(line + 1)); |
| 519 } | 519 } |
| 520 } | 520 } |
| 521 dartCodeBuffer.write(codeBuffer); | 521 dartCodeBuffer.write(codeBuffer); |
| 522 for (int line = lastLineIndex + 1; | 522 for (int line = lastLineIndex + 1; |
| 523 line <= lastLineIndex + windowSize; | 523 line <= lastLineIndex + windowSize; |
| 524 line++) { | 524 line++) { |
| 525 if (line < sourceFile.lines) { | 525 if (line < sourceFile.lines) { |
| 526 dartCodeBuffer.write(lineNumber(line, width: lineNoWidth)); | 526 dartCodeBuffer.write(lineNumber(line, width: lineNoWidth)); |
| 527 dartCodeBuffer.write(sourceFile.getLineText(line)); | 527 dartCodeBuffer.write(sourceFile.kernelSource.getTextLine(line + 1)); |
| 528 } | 528 } |
| 529 } | 529 } |
| 530 dartCodeBuffer.write('</pre>\n'); | 530 dartCodeBuffer.write('</pre>\n'); |
| 531 firstLineIndex = null; | 531 firstLineIndex = null; |
| 532 lastLineIndex = null; | 532 lastLineIndex = null; |
| 533 } | 533 } |
| 534 codeBuffer.clear(); | 534 codeBuffer.clear(); |
| 535 } | 535 } |
| 536 | 536 |
| 537 lineIndices.forEach((int lineIndex) { | 537 lineIndices.forEach((int lineIndex) { |
| 538 List<SourceLocation> locations = uriMap[lineIndex]; | 538 List<SourceLocation> locations = uriMap[lineIndex]; |
| 539 if (lastLineIndex != null && lastLineIndex + windowSize * 4 < lineIndex) { | 539 if (lastLineIndex != null && lastLineIndex + windowSize * 4 < lineIndex) { |
| 540 flush(); | 540 flush(); |
| 541 } | 541 } |
| 542 if (firstLineIndex == null) { | 542 if (firstLineIndex == null) { |
| 543 firstLineIndex = lineIndex; | 543 firstLineIndex = lineIndex; |
| 544 } else { | 544 } else { |
| 545 for (int line = lastLineIndex + 1; line < lineIndex; line++) { | 545 for (int line = lastLineIndex + 1; line < lineIndex; line++) { |
| 546 codeBuffer.write(lineNumber(line, width: lineNoWidth)); | 546 codeBuffer.write(lineNumber(line, width: lineNoWidth)); |
| 547 codeBuffer.write(sourceFile.getLineText(line)); | 547 codeBuffer.write(sourceFile.kernelSource.getTextLine(line + 1)); |
| 548 } | 548 } |
| 549 } | 549 } |
| 550 String line = sourceFile.getLineText(lineIndex); | 550 String line = sourceFile.kernelSource.getTextLine(lineIndex + 1); |
| 551 locations.sort((a, b) => a.offset.compareTo(b.offset)); | 551 locations.sort((a, b) => a.offset.compareTo(b.offset)); |
| 552 for (int i = 0; i < locations.length; i++) { | 552 for (int i = 0; i < locations.length; i++) { |
| 553 SourceLocation sourceLocation = locations[i]; | 553 SourceLocation sourceLocation = locations[i]; |
| 554 int index = collection.getIndex(sourceLocation); | 554 int index = collection.getIndex(sourceLocation); |
| 555 int start = sourceLocation.column; | 555 int start = sourceLocation.column; |
| 556 int end = line.length; | 556 int end = line.length; |
| 557 if (i + 1 < locations.length) { | 557 if (i + 1 < locations.length) { |
| 558 end = locations[i + 1].column; | 558 end = locations[i + 1].column; |
| 559 } | 559 } |
| 560 if (i == 0) { | 560 if (i == 0) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 String dartCode = truncate(codePoint.dartCode, 50); | 620 String dartCode = truncate(codePoint.dartCode, 50); |
| 621 buffer.write('<td class="code">${dartCode}</td>'); | 621 buffer.write('<td class="code">${dartCode}</td>'); |
| 622 buffer.write('<td>${escape(codePoint.sourceLocation.shortText)}</td>'); | 622 buffer.write('<td>${escape(codePoint.sourceLocation.shortText)}</td>'); |
| 623 } | 623 } |
| 624 buffer.write('</tr>'); | 624 buffer.write('</tr>'); |
| 625 }); | 625 }); |
| 626 buffer.write('</table>'); | 626 buffer.write('</table>'); |
| 627 | 627 |
| 628 return buffer.toString(); | 628 return buffer.toString(); |
| 629 } | 629 } |
| OLD | NEW |