| 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 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 String computeDartHtmlPart(String name, SourceFileManager sourceFileManager, | 480 String computeDartHtmlPart(String name, SourceFileManager sourceFileManager, |
| 481 SourceLocationCollection collection, | 481 SourceLocationCollection collection, |
| 482 {bool showAsBlock: false}) { | 482 {bool showAsBlock: false}) { |
| 483 const int windowSize = 3; | 483 const int windowSize = 3; |
| 484 StringBuffer dartCodeBuffer = new StringBuffer(); | 484 StringBuffer dartCodeBuffer = new StringBuffer(); |
| 485 Map<Uri, Map<int, List<SourceLocation>>> sourceLocationMap = {}; | 485 Map<Uri, Map<int, List<SourceLocation>>> sourceLocationMap = {}; |
| 486 collection.sourceLocations.forEach((SourceLocation sourceLocation) { | 486 collection.sourceLocations.forEach((SourceLocation sourceLocation) { |
| 487 Map<int, List<SourceLocation>> uriMap = | 487 Map<int, List<SourceLocation>> uriMap = |
| 488 sourceLocationMap.putIfAbsent(sourceLocation.sourceUri, () => {}); | 488 sourceLocationMap.putIfAbsent(sourceLocation.sourceUri, () => {}); |
| 489 List<SourceLocation> lineList = | 489 List<SourceLocation> lineList = |
| 490 uriMap.putIfAbsent(sourceLocation.line, () => []); | 490 uriMap.putIfAbsent(sourceLocation.line - 1, () => []); |
| 491 lineList.add(sourceLocation); | 491 lineList.add(sourceLocation); |
| 492 }); | 492 }); |
| 493 sourceLocationMap.forEach((Uri uri, Map<int, List<SourceLocation>> uriMap) { | 493 sourceLocationMap.forEach((Uri uri, Map<int, List<SourceLocation>> uriMap) { |
| 494 SourceFile sourceFile = sourceFileManager.getSourceFile(uri); | 494 SourceFile sourceFile = sourceFileManager.getSourceFile(uri); |
| 495 if (sourceFile == null) return; | 495 if (sourceFile == null) return; |
| 496 StringBuffer codeBuffer = new StringBuffer(); | 496 StringBuffer codeBuffer = new StringBuffer(); |
| 497 | 497 |
| 498 int firstLineIndex; | 498 int firstLineIndex; |
| 499 int lastLineIndex; | 499 int lastLineIndex; |
| 500 List<int> lineIndices = uriMap.keys.toList()..sort(); | 500 List<int> lineIndices = uriMap.keys.toList()..sort(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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.kernelSource.getTextLine(line + 1)); | 547 codeBuffer.write(sourceFile.kernelSource.getTextLine(line + 1)); |
| 548 } | 548 } |
| 549 } | 549 } |
| 550 String line = sourceFile.kernelSource.getTextLine(lineIndex + 1); | 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 - 1; |
| 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 - 1; |
| 559 } | 559 } |
| 560 if (i == 0) { | 560 if (i == 0) { |
| 561 codeBuffer.write(lineNumber(lineIndex, width: lineNoWidth)); | 561 codeBuffer.write(lineNumber(lineIndex, width: lineNoWidth)); |
| 562 codeBuffer.write(line.substring(0, start)); | 562 codeBuffer.write(line.substring(0, start)); |
| 563 } | 563 } |
| 564 codeBuffer | 564 codeBuffer |
| 565 .write('<a name="${index}" style="background:${toPattern(index)};" ' | 565 .write('<a name="${index}" style="background:${toPattern(index)};" ' |
| 566 'title="[${lineIndex + 1},${start + 1}]" ' | 566 'title="[${lineIndex + 1},${start + 1}]" ' |
| 567 'onmouseover="highlight(\'$index\');" ' | 567 'onmouseover="highlight(\'$index\');" ' |
| 568 'onmouseout="highlight();">'); | 568 'onmouseout="highlight();">'); |
| (...skipping 51 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 |