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

Side by Side Diff: pkg/analyzer_experimental/lib/src/generated/source_io.dart

Issue 23769004: java2dart improvement - use field if getter/setter are trivial. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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
OLDNEW
1 // This code was auto-generated, is not intended to be edited, and is subject to 1 // This code was auto-generated, is not intended to be edited, and is subject to
2 // significant change. Please see the README file for more information. 2 // significant change. Please see the README file for more information.
3 library engine.source.io; 3 library engine.source.io;
4 import 'source.dart'; 4 import 'source.dart';
5 import 'java_core.dart'; 5 import 'java_core.dart';
6 import 'java_io.dart'; 6 import 'java_io.dart';
7 import 'engine.dart' show AnalysisContext, AnalysisEngine; 7 import 'engine.dart' show AnalysisContext, AnalysisEngine;
8 export 'source.dart'; 8 export 'source.dart';
9 /** 9 /**
10 * Instances of the class `FileBasedSource` implement a source that represents a file. 10 * Instances of the class `FileBasedSource` implement a source that represents a file.
11 * 11 *
12 * @coverage dart.engine.source 12 * @coverage dart.engine.source
13 */ 13 */
14 class FileBasedSource implements Source { 14 class FileBasedSource implements Source {
15 15
16 /** 16 /**
17 * The content cache used to access the contents of this source if they have b een overridden from 17 * The content cache used to access the contents of this source if they have b een overridden from
18 * what is on disk or cached. 18 * what is on disk or cached.
19 */ 19 */
20 ContentCache _contentCache; 20 ContentCache _contentCache;
21 21
22 /** 22 /**
23 * The file represented by this source. 23 * The file represented by this source.
24 */ 24 */
25 JavaFile _file; 25 JavaFile file;
26 26
27 /** 27 /**
28 * The cached encoding for this source. 28 * The cached encoding for this source.
29 */ 29 */
30 String _encoding; 30 String _encoding;
31 31
32 /** 32 /**
33 * The kind of URI from which this source was originally derived. 33 * The kind of URI from which this source was originally derived.
34 */ 34 */
35 UriKind _uriKind; 35 UriKind _uriKind;
36 36
37 /** 37 /**
38 * Initialize a newly created source object. The source object is assumed to n ot be in a system 38 * Initialize a newly created source object. The source object is assumed to n ot be in a system
39 * library. 39 * library.
40 * 40 *
41 * @param contentCache the content cache used to access the contents of this s ource 41 * @param contentCache the content cache used to access the contents of this s ource
42 * @param file the file represented by this source 42 * @param file the file represented by this source
43 */ 43 */
44 FileBasedSource.con1(ContentCache contentCache, JavaFile file) : this.con2(con tentCache, file, UriKind.FILE_URI); 44 FileBasedSource.con1(ContentCache contentCache, JavaFile file) : this.con2(con tentCache, file, UriKind.FILE_URI);
45 45
46 /** 46 /**
47 * Initialize a newly created source object. 47 * Initialize a newly created source object.
48 * 48 *
49 * @param contentCache the content cache used to access the contents of this s ource 49 * @param contentCache the content cache used to access the contents of this s ource
50 * @param file the file represented by this source 50 * @param file the file represented by this source
51 * @param flags `true` if this source is in one of the system libraries 51 * @param flags `true` if this source is in one of the system libraries
52 */ 52 */
53 FileBasedSource.con2(ContentCache contentCache, JavaFile file, UriKind uriKind ) { 53 FileBasedSource.con2(ContentCache contentCache, JavaFile file, UriKind uriKind ) {
54 this._contentCache = contentCache; 54 this._contentCache = contentCache;
55 this._file = file; 55 this.file = file;
56 this._uriKind = uriKind; 56 this._uriKind = uriKind;
57 if (file.getPath().indexOf(':') > 2) { 57 if (file.getPath().indexOf(':') > 2) {
58 try { 58 try {
59 throw new IllegalArgumentException("Invalid source path: ${file}"); 59 throw new IllegalArgumentException("Invalid source path: ${file}");
60 } on IllegalArgumentException catch (e) { 60 } on IllegalArgumentException catch (e) {
61 AnalysisEngine.instance.logger.logError3(e); 61 AnalysisEngine.instance.logger.logError3(e);
62 throw e; 62 throw e;
63 } 63 }
64 } 64 }
65 } 65 }
66 bool operator ==(Object object) => object != null && this.runtimeType == objec t.runtimeType && _file == ((object as FileBasedSource))._file; 66 bool operator ==(Object object) => object != null && this.runtimeType == objec t.runtimeType && file == ((object as FileBasedSource)).file;
67 bool exists() => _contentCache.getContents(this) != null || (_file.exists() && !_file.isDirectory()); 67 bool exists() => _contentCache.getContents(this) != null || (file.exists() && !file.isDirectory());
68 void getContents(Source_ContentReceiver receiver) { 68 void getContents(Source_ContentReceiver receiver) {
69 { 69 {
70 String contents = _contentCache.getContents(this); 70 String contents = _contentCache.getContents(this);
71 if (contents != null) { 71 if (contents != null) {
72 receiver.accept2(contents, _contentCache.getModificationStamp(this)); 72 receiver.accept2(contents, _contentCache.getModificationStamp(this));
73 return; 73 return;
74 } 74 }
75 } 75 }
76 receiver.accept2(_file.readAsStringSync(), _file.lastModified()); 76 receiver.accept2(file.readAsStringSync(), file.lastModified());
77 } 77 }
78 String get encoding { 78 String get encoding {
79 if (_encoding == null) { 79 if (_encoding == null) {
80 _encoding = "${_uriKind.encoding}${_file.toURI().toString()}"; 80 _encoding = "${_uriKind.encoding}${file.toURI().toString()}";
81 } 81 }
82 return _encoding; 82 return _encoding;
83 } 83 }
84 String get fullName => _file.getAbsolutePath(); 84 String get fullName => file.getAbsolutePath();
85 int get modificationStamp { 85 int get modificationStamp {
86 int stamp = _contentCache.getModificationStamp(this); 86 int stamp = _contentCache.getModificationStamp(this);
87 if (stamp != null) { 87 if (stamp != null) {
88 return stamp; 88 return stamp;
89 } 89 }
90 return _file.lastModified(); 90 return file.lastModified();
91 } 91 }
92 String get shortName => _file.getName(); 92 String get shortName => file.getName();
93 UriKind get uriKind => _uriKind; 93 UriKind get uriKind => _uriKind;
94 int get hashCode => _file.hashCode; 94 int get hashCode => file.hashCode;
95 bool get isInSystemLibrary => identical(_uriKind, UriKind.DART_URI); 95 bool get isInSystemLibrary => identical(_uriKind, UriKind.DART_URI);
96 Source resolveRelative(Uri containedUri) { 96 Source resolveRelative(Uri containedUri) {
97 try { 97 try {
98 Uri resolvedUri = file.toURI().resolveUri(containedUri); 98 Uri resolvedUri = file.toURI().resolveUri(containedUri);
99 return new FileBasedSource.con2(_contentCache, new JavaFile.fromUri(resolv edUri), _uriKind); 99 return new FileBasedSource.con2(_contentCache, new JavaFile.fromUri(resolv edUri), _uriKind);
100 } catch (exception) { 100 } catch (exception) {
101 } 101 }
102 return null; 102 return null;
103 } 103 }
104 String toString() { 104 String toString() {
105 if (_file == null) { 105 if (file == null) {
106 return "<unknown source>"; 106 return "<unknown source>";
107 } 107 }
108 return _file.getAbsolutePath(); 108 return file.getAbsolutePath();
109 } 109 }
110
111 /**
112 * Return the file represented by this source. This is an internal method that is only intended to
113 * be used by [UriResolver].
114 *
115 * @return the file represented by this source
116 */
117 JavaFile get file => _file;
118 } 110 }
119 /** 111 /**
120 * Instances of the class `PackageUriResolver` resolve `package` URI's in the co ntext of 112 * Instances of the class `PackageUriResolver` resolve `package` URI's in the co ntext of
121 * an application. 113 * an application.
122 * 114 *
123 * For the purposes of sharing analysis, the path to each package under the "pac kages" directory 115 * For the purposes of sharing analysis, the path to each package under the "pac kages" directory
124 * should be canonicalized, but to preserve relative links within a package, the remainder of the 116 * should be canonicalized, but to preserve relative links within a package, the remainder of the
125 * path from the package directory to the leaf should not. 117 * path from the package directory to the leaf should not.
126 * 118 *
127 * @coverage dart.engine.source 119 * @coverage dart.engine.source
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 static String appendFileSeparator(String path) { 257 static String appendFileSeparator(String path) {
266 if (path == null || path.length <= 0 || path.codeUnitAt(path.length - 1) == JavaFile.separatorChar) { 258 if (path == null || path.length <= 0 || path.codeUnitAt(path.length - 1) == JavaFile.separatorChar) {
267 return path; 259 return path;
268 } 260 }
269 return "${path}${JavaFile.separator}"; 261 return "${path}${JavaFile.separator}";
270 } 262 }
271 263
272 /** 264 /**
273 * The container's path (not `null`). 265 * The container's path (not `null`).
274 */ 266 */
275 String _path; 267 String path;
276 268
277 /** 269 /**
278 * Construct a container representing the specified directory and containing a ny sources whose 270 * Construct a container representing the specified directory and containing a ny sources whose
279 * [Source#getFullName] starts with the directory's path. This is a convenienc e method, 271 * [Source#getFullName] starts with the directory's path. This is a convenienc e method,
280 * fully equivalent to [DirectoryBasedSourceContainer#DirectoryBasedSourceCont ainer] 272 * fully equivalent to [DirectoryBasedSourceContainer#DirectoryBasedSourceCont ainer]
281 * . 273 * .
282 * 274 *
283 * @param directory the directory (not `null`) 275 * @param directory the directory (not `null`)
284 */ 276 */
285 DirectoryBasedSourceContainer.con1(JavaFile directory) : this.con2(directory.g etPath()); 277 DirectoryBasedSourceContainer.con1(JavaFile directory) : this.con2(directory.g etPath());
286 278
287 /** 279 /**
288 * Construct a container representing the specified path and containing any so urces whose 280 * Construct a container representing the specified path and containing any so urces whose
289 * [Source#getFullName] starts with the specified path. 281 * [Source#getFullName] starts with the specified path.
290 * 282 *
291 * @param path the path (not `null` and not empty) 283 * @param path the path (not `null` and not empty)
292 */ 284 */
293 DirectoryBasedSourceContainer.con2(String path) { 285 DirectoryBasedSourceContainer.con2(String path) {
294 this._path = appendFileSeparator(path); 286 this.path = appendFileSeparator(path);
295 } 287 }
296 bool contains(Source source) => source.fullName.startsWith(_path); 288 bool contains(Source source) => source.fullName.startsWith(path);
297 bool operator ==(Object obj) => (obj is DirectoryBasedSourceContainer) && ((ob j as DirectoryBasedSourceContainer)).path == path; 289 bool operator ==(Object obj) => (obj is DirectoryBasedSourceContainer) && ((ob j as DirectoryBasedSourceContainer)).path == path;
298 290 int get hashCode => path.hashCode;
299 /** 291 String toString() => "SourceContainer[${path}]";
300 * Answer the receiver's path, used to determine if a source is contained in t he receiver.
301 *
302 * @return the path (not `null`, not empty)
303 */
304 String get path => _path;
305 int get hashCode => _path.hashCode;
306 String toString() => "SourceContainer[${_path}]";
307 } 292 }
308 /** 293 /**
309 * Instances of the class `FileUriResolver` resolve `file` URI's. 294 * Instances of the class `FileUriResolver` resolve `file` URI's.
310 * 295 *
311 * @coverage dart.engine.source 296 * @coverage dart.engine.source
312 */ 297 */
313 class FileUriResolver extends UriResolver { 298 class FileUriResolver extends UriResolver {
314 299
315 /** 300 /**
316 * The name of the `file` scheme. 301 * The name of the `file` scheme.
(...skipping 13 matching lines...) Expand all
330 } 315 }
331 return null; 316 return null;
332 } 317 }
333 Source resolveAbsolute(ContentCache contentCache, Uri uri) { 318 Source resolveAbsolute(ContentCache contentCache, Uri uri) {
334 if (!isFileUri(uri)) { 319 if (!isFileUri(uri)) {
335 return null; 320 return null;
336 } 321 }
337 return new FileBasedSource.con1(contentCache, new JavaFile.fromUri(uri)); 322 return new FileBasedSource.con1(contentCache, new JavaFile.fromUri(uri));
338 } 323 }
339 } 324 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698