OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // TODO(jimhug): This should be an interface to work better with tools. | 5 // TODO(jimhug): This should be an interface to work better with tools. |
6 /** | 6 /** |
7 * Represents a file of source code. | 7 * Represents a file of source code. |
8 */ | 8 */ |
9 class SourceFile implements Comparable<SourceFile> { | 9 class SourceFile implements Comparable<SourceFile> { |
10 // TODO(terry): This filename for in memory buffer. May need to rework if | 10 // TODO(terry): This filename for in memory buffer. May need to rework if |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 * in the file. | 73 * in the file. |
74 */ | 74 */ |
75 String getLocationMessage(String message, int start, | 75 String getLocationMessage(String message, int start, |
76 [int end, bool includeText=false]) { | 76 [int end, bool includeText=false]) { |
77 var line = getLine(start); | 77 var line = getLine(start); |
78 var column = getColumn(line, start); | 78 var column = getColumn(line, start); |
79 | 79 |
80 var buf = new StringBuffer( | 80 var buf = new StringBuffer( |
81 '${filename}:${line + 1}:${column + 1}: $message'); | 81 '${filename}:${line + 1}:${column + 1}: $message'); |
82 if (includeText) { | 82 if (includeText) { |
83 buf.add('\n'); | 83 buf.write('\n'); |
84 var textLine; | 84 var textLine; |
85 // +1 for 0-indexing, +1 again to avoid the last line of the file | 85 // +1 for 0-indexing, +1 again to avoid the last line of the file |
86 if ((line + 2) < _lineStarts.length) { | 86 if ((line + 2) < _lineStarts.length) { |
87 textLine = text.substring(_lineStarts[line], _lineStarts[line+1]); | 87 textLine = text.substring(_lineStarts[line], _lineStarts[line+1]); |
88 } else { | 88 } else { |
89 textLine = text.substring(_lineStarts[line]) + '\n'; | 89 textLine = text.substring(_lineStarts[line]) + '\n'; |
90 } | 90 } |
91 | 91 |
92 int toColumn = Math.min(column + (end-start), textLine.length); | 92 int toColumn = Math.min(column + (end-start), textLine.length); |
93 if (options.useColors) { | 93 if (options.useColors) { |
94 buf.add(textLine.substring(0, column)); | 94 buf.write(textLine.substring(0, column)); |
95 buf.add(_RED_COLOR); | 95 buf.write(_RED_COLOR); |
96 buf.add(textLine.substring(column, toColumn)); | 96 buf.write(textLine.substring(column, toColumn)); |
97 buf.add(_NO_COLOR); | 97 buf.write(_NO_COLOR); |
98 buf.add(textLine.substring(toColumn)); | 98 buf.write(textLine.substring(toColumn)); |
99 } else { | 99 } else { |
100 buf.add(textLine); | 100 buf.write(textLine); |
101 } | 101 } |
102 | 102 |
103 int i = 0; | 103 int i = 0; |
104 for (; i < column; i++) { | 104 for (; i < column; i++) { |
105 buf.add(' '); | 105 buf.write(' '); |
106 } | 106 } |
107 | 107 |
108 if (options.useColors) buf.add(_RED_COLOR); | 108 if (options.useColors) buf.write(_RED_COLOR); |
109 for (; i < toColumn; i++) { | 109 for (; i < toColumn; i++) { |
110 buf.add('^'); | 110 buf.write('^'); |
111 } | 111 } |
112 if (options.useColors) buf.add(_NO_COLOR); | 112 if (options.useColors) buf.write(_NO_COLOR); |
113 } | 113 } |
114 | 114 |
115 return buf.toString(); | 115 return buf.toString(); |
116 } | 116 } |
117 | 117 |
118 /** Compares two source files. */ | 118 /** Compares two source files. */ |
119 int compareTo(SourceFile other) { | 119 int compareTo(SourceFile other) { |
120 if (orderInLibrary != null && other.orderInLibrary != null) { | 120 if (orderInLibrary != null && other.orderInLibrary != null) { |
121 return orderInLibrary - other.orderInLibrary; | 121 return orderInLibrary - other.orderInLibrary; |
122 } else { | 122 } else { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 177 |
178 /** Compares two source spans by file and position. Handles nulls. */ | 178 /** Compares two source spans by file and position. Handles nulls. */ |
179 int compareTo(SourceSpan other) { | 179 int compareTo(SourceSpan other) { |
180 if (file == other.file) { | 180 if (file == other.file) { |
181 int d = start - other.start; | 181 int d = start - other.start; |
182 return d == 0 ? (end - other.end) : d; | 182 return d == 0 ? (end - other.end) : d; |
183 } | 183 } |
184 return file.compareTo(other.file); | 184 return file.compareTo(other.file); |
185 } | 185 } |
186 } | 186 } |
OLD | NEW |