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

Side by Side Diff: tests/compiler/dart2js/source_map_validator_helper.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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 import 'dart:io'; 5 import 'dart:io';
6 import 'dart:convert'; 6 import 'dart:convert';
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:path/path.dart' as path; 9 import 'package:path/path.dart' as path;
10 import 'package:expect/expect.dart'; 10 import 'package:expect/expect.dart';
11 import 'package:source_maps/source_maps.dart'; 11 import 'package:source_maps/source_maps.dart';
12 import 'package:compiler/src/apiimpl.dart'; 12 import 'package:compiler/src/apiimpl.dart';
13 import 'package:compiler/src/elements/elements.dart' 13 import 'package:compiler/src/elements/elements.dart'
14 show 14 show
15 AstElement, 15 AstElement,
16 ClassElement, 16 ClassElement,
17 CompilationUnitElement, 17 CompilationUnitElement,
18 Element, 18 Element,
19 FunctionElement, 19 FunctionElement,
20 LibraryElement, 20 LibraryElement,
21 MemberElement; 21 MemberElement;
22 import 'package:compiler/src/io/source_file.dart' show SourceFile; 22 import 'package:compiler/src/io/source_file.dart' show SourceFile;
23 import 'package:compiler/src/io/source_information.dart' 23 import 'package:compiler/src/io/source_information.dart'
24 show computeElementNameForSourceMaps; 24 show computeElementNameForSourceMaps;
25 import 'package:kernel/ast.dart' show Location;
25 26
26 validateSourceMap(Uri targetUri, 27 validateSourceMap(Uri targetUri,
27 {Uri mainUri, Position mainPosition, CompilerImpl compiler}) { 28 {Uri mainUri, Position mainPosition, CompilerImpl compiler}) {
28 Uri mapUri = getMapUri(targetUri); 29 Uri mapUri = getMapUri(targetUri);
29 List<String> targetLines = new File.fromUri(targetUri).readAsLinesSync(); 30 List<String> targetLines = new File.fromUri(targetUri).readAsLinesSync();
30 SingleMapping sourceMap = getSourceMap(mapUri); 31 SingleMapping sourceMap = getSourceMap(mapUri);
31 checkFileReferences(targetUri, mapUri, sourceMap); 32 checkFileReferences(targetUri, mapUri, sourceMap);
32 checkIndexReferences(targetLines, mapUri, sourceMap); 33 checkIndexReferences(targetLines, mapUri, sourceMap);
33 checkRedundancy(sourceMap); 34 checkRedundancy(sourceMap);
34 if (compiler != null) { 35 if (compiler != null) {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 new Position(entry.sourceLine, entry.sourceColumn); 126 new Position(entry.sourceLine, entry.sourceColumn);
126 String name = sourceMap.names[entry.sourceNameId]; 127 String name = sourceMap.names[entry.sourceNameId];
127 128
128 CompilationUnitElement compilationUnit = compilationUnitMap[uri]; 129 CompilationUnitElement compilationUnit = compilationUnitMap[uri];
129 Expect.isNotNull( 130 Expect.isNotNull(
130 compilationUnit, "No compilation unit found for $uri."); 131 compilationUnit, "No compilation unit found for $uri.");
131 132
132 SourceFile sourceFile = compilationUnit.script.file; 133 SourceFile sourceFile = compilationUnit.script.file;
133 134
134 Position positionFromOffset(int offset) { 135 Position positionFromOffset(int offset) {
135 int line = sourceFile.getLine(offset); 136 Location location = sourceFile.getLocation(offset);
136 int column = sourceFile.getColumn(line, offset); 137 int line = location.line - 1;
138 int column = location.column - 1;
137 return new Position(line, column); 139 return new Position(line, column);
138 } 140 }
139 141
140 Interval intervalFromElement(AstElement element) { 142 Interval intervalFromElement(AstElement element) {
141 if (!element.hasNode) return null; 143 if (!element.hasNode) return null;
142 144
143 var begin = element.node.getBeginToken().charOffset; 145 var begin = element.node.getBeginToken().charOffset;
144 var end = element.node.getEndToken(); 146 var end = element.node.getEndToken();
145 end = end.charOffset + end.charCount; 147 end = end.charOffset + end.charCount;
146 return new Interval( 148 return new Interval(
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 final Position end; 317 final Position end;
316 318
317 Interval(this.begin, this.end); 319 Interval(this.begin, this.end);
318 320
319 bool contains(Position other) { 321 bool contains(Position other) {
320 return begin <= other && other <= end; 322 return begin <= other && other <= end;
321 } 323 }
322 324
323 String toString() => '$begin-$end'; 325 String toString() => '$begin-$end';
324 } 326 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698