Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: tests/compiler/dart2js/sourcemaps/diff.dart

Issue 2788373002: Add Source.getTextLine and use it to display source snippets in error messages. (Closed)
Patch Set: dartfmt Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 sourcemap.diff; 5 library sourcemap.diff;
6 6
7 import 'package:compiler/src/io/source_file.dart'; 7 import 'package:compiler/src/io/source_file.dart';
8 8
9 import 'html_parts.dart'; 9 import 'html_parts.dart';
10 import 'output_structure.dart'; 10 import 'output_structure.dart';
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 addSkewedEntity(index, parent.getChild(i)); 440 addSkewedEntity(index, parent.getChild(i));
441 } 441 }
442 } 442 }
443 443
444 /// Adds the members of the [classes] aligned. 444 /// Adds the members of the [classes] aligned.
445 void addMatchingContainers(List<OutputEntity> classes) { 445 void addMatchingContainers(List<OutputEntity> classes) {
446 addLines(DiffKind.MATCHING, classes.map((c) => c.header).toList()); 446 addLines(DiffKind.MATCHING, classes.map((c) => c.header).toList());
447 align(classes[0].children, classes[1].children, 447 align(classes[0].children, classes[1].children,
448 match: (a, b) => a.name == b.name, 448 match: (a, b) => a.name == b.name,
449 handleSkew: (int listIndex, Interval childRange) { 449 handleSkew: (int listIndex, Interval childRange) {
450 addSkewedChildren(listIndex, classes[listIndex], childRange); 450 addSkewedChildren(listIndex, classes[listIndex], childRange);
451 }, handleMatched: (List<int> indices) { 451 },
452 List<BasicEntity> entities = [ 452 handleMatched: (List<int> indices) {
453 classes[0].getChild(indices[0]), 453 List<BasicEntity> entities = [
454 classes[1].getChild(indices[1]) 454 classes[0].getChild(indices[0]),
455 ]; 455 classes[1].getChild(indices[1])
456 if (entities.every((e) => e is Statics)) { 456 ];
457 addMatchingContainers(entities); 457 if (entities.every((e) => e is Statics)) {
458 } else { 458 addMatchingContainers(entities);
459 addLines(DiffKind.MATCHING, entities.map((e) => e.interval).toList(), 459 } else {
460 codeSourceFromEntities(entities)); 460 addLines(
461 } 461 DiffKind.MATCHING,
462 }, handleUnmatched: (List<int> indices) { 462 entities.map((e) => e.interval).toList(),
463 List<Interval> intervals = [ 463 codeSourceFromEntities(entities));
464 classes[0].getChild(indices[0]).interval, 464 }
465 classes[1].getChild(indices[1]).interval 465 },
466 ]; 466 handleUnmatched: (List<int> indices) {
467 addLines(DiffKind.UNMATCHED, intervals); 467 List<Interval> intervals = [
468 }); 468 classes[0].getChild(indices[0]).interval,
469 classes[1].getChild(indices[1]).interval
470 ];
471 addLines(DiffKind.UNMATCHED, intervals);
472 });
469 addLines(DiffKind.MATCHING, classes.map((c) => c.footer).toList()); 473 addLines(DiffKind.MATCHING, classes.map((c) => c.footer).toList());
470 } 474 }
471 475
472 /// Adds the library blocks in [indices] from the corresponding 476 /// Adds the library blocks in [indices] from the corresponding
473 /// [OutputStructure]s, aligning their content. 477 /// [OutputStructure]s, aligning their content.
474 void addMatchingBlocks(List<int> indices) { 478 void addMatchingBlocks(List<int> indices) {
475 List<LibraryBlock> blocks = [ 479 List<LibraryBlock> blocks = [
476 structures[0].getChild(indices[0]), 480 structures[0].getChild(indices[0]),
477 structures[1].getChild(indices[1]) 481 structures[1].getChild(indices[1])
478 ]; 482 ];
479 483
480 addLines(DiffKind.MATCHING, blocks.map((b) => b.header).toList()); 484 addLines(DiffKind.MATCHING, blocks.map((b) => b.header).toList());
481 align(blocks[0].children, blocks[1].children, 485 align(blocks[0].children, blocks[1].children,
482 match: (a, b) => a.name == b.name, 486 match: (a, b) => a.name == b.name,
483 handleSkew: (int listIndex, Interval childRange) { 487 handleSkew: (int listIndex, Interval childRange) {
484 addSkewedChildren(listIndex, blocks[listIndex], childRange); 488 addSkewedChildren(listIndex, blocks[listIndex], childRange);
485 }, handleMatched: (List<int> indices) { 489 },
486 List<BasicEntity> entities = [ 490 handleMatched: (List<int> indices) {
487 blocks[0].getChild(indices[0]), 491 List<BasicEntity> entities = [
488 blocks[1].getChild(indices[1]) 492 blocks[0].getChild(indices[0]),
489 ]; 493 blocks[1].getChild(indices[1])
490 if (entities.every((e) => e is LibraryClass)) { 494 ];
491 addMatchingContainers(entities); 495 if (entities.every((e) => e is LibraryClass)) {
492 } else { 496 addMatchingContainers(entities);
493 addLines(DiffKind.MATCHING, entities.map((e) => e.interval).toList(), 497 } else {
494 codeSourceFromEntities(entities)); 498 addLines(
495 } 499 DiffKind.MATCHING,
496 }, handleUnmatched: (List<int> indices) { 500 entities.map((e) => e.interval).toList(),
497 List<Interval> intervals = [ 501 codeSourceFromEntities(entities));
498 blocks[0].getChild(indices[0]).interval, 502 }
499 blocks[1].getChild(indices[1]).interval 503 },
500 ]; 504 handleUnmatched: (List<int> indices) {
501 addLines(DiffKind.UNMATCHED, intervals); 505 List<Interval> intervals = [
502 }); 506 blocks[0].getChild(indices[0]).interval,
507 blocks[1].getChild(indices[1]).interval
508 ];
509 addLines(DiffKind.UNMATCHED, intervals);
510 });
503 addLines(DiffKind.MATCHING, blocks.map((b) => b.footer).toList()); 511 addLines(DiffKind.MATCHING, blocks.map((b) => b.footer).toList());
504 } 512 }
505 513
506 /// Adds the lines of the blocks in [indices] from the corresponding 514 /// Adds the lines of the blocks in [indices] from the corresponding
507 /// [OutputStructure]s. 515 /// [OutputStructure]s.
508 void addUnmatchedBlocks(List<int> indices) { 516 void addUnmatchedBlocks(List<int> indices) {
509 List<LibraryBlock> blocks = [ 517 List<LibraryBlock> blocks = [
510 structures[0].getChild(indices[0]), 518 structures[0].getChild(indices[0]),
511 structures[1].getChild(indices[1]) 519 structures[1].getChild(indices[1])
512 ]; 520 ];
(...skipping 20 matching lines...) Expand all
533 List<HtmlPart> codeLinesFromCodeSource(CodeSource codeSource) { 541 List<HtmlPart> codeLinesFromCodeSource(CodeSource codeSource) {
534 List<HtmlPart> lines = <HtmlPart>[]; 542 List<HtmlPart> lines = <HtmlPart>[];
535 SourceFile sourceFile = sourceFileManager.getSourceFile(codeSource.uri); 543 SourceFile sourceFile = sourceFileManager.getSourceFile(codeSource.uri);
536 String elementName = codeSource.name; 544 String elementName = codeSource.name;
537 HtmlLine line = new HtmlLine(); 545 HtmlLine line = new HtmlLine();
538 line.htmlParts.add(new ConstHtmlPart('<span class="comment">')); 546 line.htmlParts.add(new ConstHtmlPart('<span class="comment">'));
539 line.htmlParts.add(new HtmlText('${elementName}: ${sourceFile.filename}')); 547 line.htmlParts.add(new HtmlText('${elementName}: ${sourceFile.filename}'));
540 line.htmlParts.add(new ConstHtmlPart('</span>')); 548 line.htmlParts.add(new ConstHtmlPart('</span>'));
541 lines.add(line); 549 lines.add(line);
542 if (codeSource.begin != null) { 550 if (codeSource.begin != null) {
543 int startLine = sourceFile.getLine(codeSource.begin); 551 int startLine = sourceFile.getLocation(codeSource.begin).line - 1;
544 int endLine = sourceFile.getLine(codeSource.end) + 1; 552 int endLine = sourceFile.getLocation(codeSource.end).line;
545 for (CodeLine codeLine in convertAnnotatedCodeToCodeLines( 553 for (CodeLine codeLine in convertAnnotatedCodeToCodeLines(
546 sourceFile.slowText(), const <Annotation>[], 554 sourceFile.slowText(), const <Annotation>[],
547 startLine: startLine, endLine: endLine)) { 555 startLine: startLine, endLine: endLine)) {
548 codeLine.lineAnnotation = codeSource; 556 codeLine.lineAnnotation = codeSource;
549 lines.add(codeLine); 557 lines.add(codeLine);
550 } 558 }
551 } 559 }
552 return lines; 560 return lines;
553 } 561 }
554 562
(...skipping 30 matching lines...) Expand all
585 startLine: interval.from, endLine: interval.to, uri: currentUri); 593 startLine: interval.from, endLine: interval.to, uri: currentUri);
586 if (codeSources != null) { 594 if (codeSources != null) {
587 CodeSource currentCodeSource; 595 CodeSource currentCodeSource;
588 Interval currentLineInterval; 596 Interval currentLineInterval;
589 for (CodeLine dartCodeLine in annotatedDartCodeLines) { 597 for (CodeLine dartCodeLine in annotatedDartCodeLines) {
590 if (currentCodeSource == null || 598 if (currentCodeSource == null ||
591 !currentLineInterval.contains(dartCodeLine.lineNo)) { 599 !currentLineInterval.contains(dartCodeLine.lineNo)) {
592 currentCodeSource = null; 600 currentCodeSource = null;
593 for (CodeSource codeSource in codeSources) { 601 for (CodeSource codeSource in codeSources) {
594 Interval interval = new Interval( 602 Interval interval = new Interval(
595 sourceFile.getLine(codeSource.begin), 603 sourceFile.getLocation(codeSource.begin).line - 1,
596 sourceFile.getLine(codeSource.end) + 1); 604 sourceFile.getLocation(codeSource.end).line);
597 if (interval.contains(dartCodeLine.lineNo)) { 605 if (interval.contains(dartCodeLine.lineNo)) {
598 currentCodeSource = codeSource; 606 currentCodeSource = codeSource;
599 currentLineInterval = interval; 607 currentLineInterval = interval;
600 break; 608 break;
601 } 609 }
602 } 610 }
603 } 611 }
604 if (currentCodeSource != null) { 612 if (currentCodeSource != null) {
605 dartCodeLine.lineAnnotation = currentCodeSource; 613 dartCodeLine.lineAnnotation = currentCodeSource;
606 } 614 }
(...skipping 25 matching lines...) Expand all
632 codeLineInterval.clear(); 640 codeLineInterval.clear();
633 codeLineInterval[codeLine] = interval; 641 codeLineInterval[codeLine] = interval;
634 } 642 }
635 643
636 for (CodeLine jsCodeLine in jsCodeLines) { 644 for (CodeLine jsCodeLine in jsCodeLines) {
637 for (Annotation annotation in jsCodeLine.annotations) { 645 for (Annotation annotation in jsCodeLine.annotations) {
638 CodeLineAnnotation codeLineAnnotation = annotation.data; 646 CodeLineAnnotation codeLineAnnotation = annotation.data;
639 647
640 for (CodeLocation location in codeLineAnnotation.codeLocations) { 648 for (CodeLocation location in codeLineAnnotation.codeLocations) {
641 SourceFile sourceFile = sourceFileManager.getSourceFile(location.uri); 649 SourceFile sourceFile = sourceFileManager.getSourceFile(location.uri);
642 int line = sourceFile.getLine(location.offset); 650 int line = sourceFile.getLocation(location.offset).line - 1;
643 if (currentUri != location.uri) { 651 if (currentUri != location.uri) {
644 restart(jsCodeLine, location, line); 652 restart(jsCodeLine, location, line);
645 } else if (interval.inWindow(line, windowSize: 2)) { 653 } else if (interval.inWindow(line, windowSize: 2)) {
646 interval = interval.include(line); 654 interval = interval.include(line);
647 codeLineInterval[jsCodeLine] = interval; 655 codeLineInterval[jsCodeLine] = interval;
648 } else { 656 } else {
649 restart(jsCodeLine, location, line); 657 restart(jsCodeLine, location, line);
650 } 658 }
651 659
652 annotations.add(new Annotation(codeLineAnnotation.annotationType, 660 annotations.add(new Annotation(codeLineAnnotation.annotationType,
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 annotationType: AnnotationType.values[json['annotationType']], 767 annotationType: AnnotationType.values[json['annotationType']],
760 codeLocations: json['codeLocations'] 768 codeLocations: json['codeLocations']
761 .map((j) => CodeLocation.fromJson(j, strategy)) 769 .map((j) => CodeLocation.fromJson(j, strategy))
762 .toList(), 770 .toList(),
763 codeSources: 771 codeSources:
764 json['codeSources'].map((j) => CodeSource.fromJson(j)).toList(), 772 json['codeSources'].map((j) => CodeSource.fromJson(j)).toList(),
765 stepInfo: json['stepInfo'], 773 stepInfo: json['stepInfo'],
766 sourceMappingIndex: json['sourceMappingIndex']); 774 sourceMappingIndex: json['sourceMappingIndex']);
767 } 775 }
768 } 776 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698