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

Side by Side Diff: dart/lib/compiler/implementation/source_file.dart

Issue 10579015: Update dart2js to use diagnostic kinds. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « dart/lib/compiler/implementation/leg.dart ('k') | dart/tests/utils/dummy_compiler_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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('source_file'); 5 #library('source_file');
6 6
7 #import('colors.dart', prefix: 'colors'); 7 #import('colors.dart', prefix: 'colors');
8 8
9 /** 9 /**
10 * Represents a file of source code. 10 * Represents a file of source code.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 } 46 }
47 47
48 int getColumn(int line, int position) { 48 int getColumn(int line, int position) {
49 return position - lineStarts[line]; 49 return position - lineStarts[line];
50 } 50 }
51 51
52 /** 52 /**
53 * Create a pretty string representation from a character position 53 * Create a pretty string representation from a character position
54 * in the file. 54 * in the file.
55 */ 55 */
56 String getLocationMessage(String message, int start, 56 String getLocationMessage(String message, int start, int end,
57 [int end, bool includeText = false]) { 57 bool includeText, String color(String x)) {
58 var line = getLine(start); 58 var line = getLine(start);
59 var column = getColumn(line, start); 59 var column = getColumn(line, start);
60 60
61 var buf = new StringBuffer( 61 var buf = new StringBuffer(
62 '${filename}:${line + 1}:${column + 1}: $message'); 62 '${filename}:${line + 1}:${column + 1}: $message');
63 if (includeText) { 63 if (includeText) {
64 buf.add('\n'); 64 buf.add('\n');
65 var textLine; 65 var textLine;
66 // +1 for 0-indexing, +1 again to avoid the last line of the file 66 // +1 for 0-indexing, +1 again to avoid the last line of the file
67 if ((line + 2) < _lineStarts.length) { 67 if ((line + 2) < _lineStarts.length) {
68 textLine = text.substring(_lineStarts[line], _lineStarts[line+1]); 68 textLine = text.substring(_lineStarts[line], _lineStarts[line+1]);
69 } else { 69 } else {
70 textLine = '${text.substring(_lineStarts[line])}\n'; 70 textLine = '${text.substring(_lineStarts[line])}\n';
71 } 71 }
72 72
73 int toColumn = Math.min(column + (end-start), textLine.length); 73 int toColumn = Math.min(column + (end-start), textLine.length);
74 if (colors.enabled) { 74 buf.add(textLine.substring(0, column));
75 buf.add(textLine.substring(0, column)); 75 buf.add(color(textLine.substring(column, toColumn)));
76 buf.add(colors.RED_COLOR); 76 buf.add(textLine.substring(toColumn));
77 buf.add(textLine.substring(column, toColumn));
78 buf.add(colors.NO_COLOR);
79 buf.add(textLine.substring(toColumn));
80 } else {
81 buf.add(textLine);
82 }
83 77
84 int i = 0; 78 int i = 0;
85 for (; i < column; i++) { 79 for (; i < column; i++) {
86 buf.add(' '); 80 buf.add(' ');
87 } 81 }
88 82
89 if (colors.enabled) buf.add(colors.RED_COLOR);
90 for (; i < toColumn; i++) { 83 for (; i < toColumn; i++) {
91 buf.add('^'); 84 buf.add(color('^'));
92 } 85 }
93 if (colors.enabled) buf.add(colors.NO_COLOR);
94 } 86 }
95 87
96 return buf.toString(); 88 return buf.toString();
97 } 89 }
98 } 90 }
OLDNEW
« no previous file with comments | « dart/lib/compiler/implementation/leg.dart ('k') | dart/tests/utils/dummy_compiler_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698