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

Side by Side Diff: utils/template/source.dart

Issue 10919146: Get rid of a lot of () for getters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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 | « utils/template/parser.dart ('k') | utils/template/token.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) 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 { 9 class SourceFile implements Comparable {
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 12 matching lines...) Expand all
23 */ 23 */
24 // TODO(jmesserly): I don't like having properties that are only valid 24 // TODO(jmesserly): I don't like having properties that are only valid
25 // sometimes. An alternative would be to store it in a Map that's used by 25 // sometimes. An alternative would be to store it in a Map that's used by
26 // WorldGenerator while it's emitting code. This seems simpler. 26 // WorldGenerator while it's emitting code. This seems simpler.
27 int orderInLibrary; 27 int orderInLibrary;
28 28
29 List<int> _lineStarts; 29 List<int> _lineStarts;
30 30
31 SourceFile(this.filename, this._text); 31 SourceFile(this.filename, this._text);
32 32
33 String get text() => _text; 33 String get text => _text;
34 34
35 set text(String newText) { 35 set text(String newText) {
36 if (newText != _text) { 36 if (newText != _text) {
37 _text = newText; 37 _text = newText;
38 _lineStarts = null; 38 _lineStarts = null;
39 orderInLibrary = null; 39 orderInLibrary = null;
40 } 40 }
41 } 41 }
42 42
43 List<int> get lineStarts() { 43 List<int> get lineStarts {
44 if (_lineStarts == null) { 44 if (_lineStarts == null) {
45 var starts = [0]; 45 var starts = [0];
46 var index = 0; 46 var index = 0;
47 while (index < text.length) { 47 while (index < text.length) {
48 index = text.indexOf('\n', index) + 1; 48 index = text.indexOf('\n', index) + 1;
49 if (index <= 0) break; 49 if (index <= 0) break;
50 starts.add(index); 50 starts.add(index);
51 } 51 }
52 starts.add(text.length + 1); 52 starts.add(text.length + 1);
53 _lineStarts = starts; 53 _lineStarts = starts;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 138
139 /** The character position of the start of this span. */ 139 /** The character position of the start of this span. */
140 final int start; 140 final int start;
141 141
142 /** The character position of the end of this span. */ 142 /** The character position of the end of this span. */
143 final int end; 143 final int end;
144 144
145 SourceSpan(this.file, this.start, this.end); 145 SourceSpan(this.file, this.start, this.end);
146 146
147 /** Returns the source text corresponding to this [Span]. */ 147 /** Returns the source text corresponding to this [Span]. */
148 String get text() { 148 String get text {
149 return file.text.substring(start, end); 149 return file.text.substring(start, end);
150 } 150 }
151 151
152 toMessageString(String message) { 152 toMessageString(String message) {
153 return file.getLocationMessage(message, start, end: end, includeText: true); 153 return file.getLocationMessage(message, start, end: end, includeText: true);
154 } 154 }
155 155
156 int get line() { 156 int get line {
157 return file.getLine(start); 157 return file.getLine(start);
158 } 158 }
159 159
160 int get column() { 160 int get column {
161 return file.getColumn(line, start); 161 return file.getColumn(line, start);
162 } 162 }
163 163
164 int get endLine() { 164 int get endLine {
165 return file.getLine(end); 165 return file.getLine(end);
166 } 166 }
167 167
168 int get endColumn() { 168 int get endColumn {
169 return file.getColumn(endLine, end); 169 return file.getColumn(endLine, end);
170 } 170 }
171 171
172 String get locationText() { 172 String get locationText {
173 var line = file.getLine(start); 173 var line = file.getLine(start);
174 var column = file.getColumn(line, start); 174 var column = file.getColumn(line, start);
175 return '${file.filename}:${line + 1}:${column + 1}'; 175 return '${file.filename}:${line + 1}:${column + 1}';
176 } 176 }
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 }
OLDNEW
« no previous file with comments | « utils/template/parser.dart ('k') | utils/template/token.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698