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

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

Issue 184893003: New analyzer snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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 // 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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.source.io; 8 library engine.source.io;
9 9
10 import 'source.dart'; 10 import 'source.dart';
11 import 'java_core.dart'; 11 import 'java_core.dart';
12 import 'java_io.dart'; 12 import 'java_io.dart';
13 import 'engine.dart' show AnalysisContext, AnalysisEngine; 13 import 'engine.dart' show AnalysisContext, AnalysisEngine, TimestampedData;
14 export 'source.dart'; 14 export 'source.dart';
15 15
16 /** 16 /**
17 * Instances of interface `LocalSourcePredicate` are used to determine if the gi ven 17 * Instances of interface `LocalSourcePredicate` are used to determine if the gi ven
18 * [Source] is "local" in some sense, so can be updated. 18 * [Source] is "local" in some sense, so can be updated.
19 * 19 *
20 * @coverage dart.engine.source 20 * @coverage dart.engine.source
21 */ 21 */
22 abstract class LocalSourcePredicate { 22 abstract class LocalSourcePredicate {
23 /** 23 /**
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 bool isLocal(Source source) => source.uriKind != UriKind.DART_URI; 57 bool isLocal(Source source) => source.uriKind != UriKind.DART_URI;
58 } 58 }
59 59
60 /** 60 /**
61 * Instances of the class `FileBasedSource` implement a source that represents a file. 61 * Instances of the class `FileBasedSource` implement a source that represents a file.
62 * 62 *
63 * @coverage dart.engine.source 63 * @coverage dart.engine.source
64 */ 64 */
65 class FileBasedSource implements Source { 65 class FileBasedSource implements Source {
66 /** 66 /**
67 * The content cache used to access the contents of this source if they have b een overridden from
68 * what is on disk or cached.
69 */
70 ContentCache _contentCache;
71
72 /**
73 * The file represented by this source. 67 * The file represented by this source.
74 */ 68 */
75 JavaFile _file; 69 JavaFile _file;
76 70
77 /** 71 /**
78 * The cached encoding for this source. 72 * The cached encoding for this source.
79 */ 73 */
80 String _encoding; 74 String _encoding;
81 75
82 /** 76 /**
83 * The kind of URI from which this source was originally derived. 77 * The kind of URI from which this source was originally derived.
84 */ 78 */
85 UriKind _uriKind; 79 UriKind _uriKind;
86 80
87 /** 81 /**
88 * Initialize a newly created source object. The source object is assumed to n ot be in a system 82 * Initialize a newly created source object. The source object is assumed to n ot be in a system
89 * library. 83 * library.
90 * 84 *
91 * @param contentCache the content cache used to access the contents of this s ource
92 * @param file the file represented by this source 85 * @param file the file represented by this source
93 */ 86 */
94 FileBasedSource.con1(ContentCache contentCache, JavaFile file) : this.con2(con tentCache, file, UriKind.FILE_URI); 87 FileBasedSource.con1(JavaFile file) : this.con2(file, UriKind.FILE_URI);
95 88
96 /** 89 /**
97 * Initialize a newly created source object. 90 * Initialize a newly created source object.
98 * 91 *
99 * @param contentCache the content cache used to access the contents of this s ource
100 * @param file the file represented by this source 92 * @param file the file represented by this source
101 * @param flags `true` if this source is in one of the system libraries 93 * @param flags `true` if this source is in one of the system libraries
102 */ 94 */
103 FileBasedSource.con2(ContentCache contentCache, JavaFile file, UriKind uriKind ) { 95 FileBasedSource.con2(JavaFile file, UriKind uriKind) {
104 this._contentCache = contentCache;
105 this._file = file; 96 this._file = file;
106 this._uriKind = uriKind; 97 this._uriKind = uriKind;
107 } 98 }
108 99
109 bool operator ==(Object object) => object != null && this.runtimeType == objec t.runtimeType && _file == (object as FileBasedSource)._file; 100 bool operator ==(Object object) => object != null && this.runtimeType == objec t.runtimeType && _file == (object as FileBasedSource)._file;
110 101
111 bool exists() => _contentCache.getContents(this) != null || _file.isFile(); 102 bool exists() => _file.isFile();
112 103
113 void getContents(Source_ContentReceiver receiver) { 104 TimestampedData<String> get contents => contentsFromFile;
114 // 105
115 // First check to see whether our content cache has an override for our cont ents. 106 void getContentsToReceiver(Source_ContentReceiver receiver) {
116 // 107 getContentsFromFileToReceiver(receiver);
117 String contents = _contentCache.getContents(this);
118 if (contents != null) {
119 receiver.accept(contents, _contentCache.getModificationStamp(this));
120 return;
121 }
122 //
123 // If not, read the contents from the file using native I/O.
124 //
125 getContentsFromFile(receiver);
126 } 108 }
127 109
128 String get encoding { 110 String get encoding {
129 if (_encoding == null) { 111 if (_encoding == null) {
130 _encoding = "${_uriKind.encoding}${_file.toURI().toString()}"; 112 _encoding = "${_uriKind.encoding}${_file.toURI().toString()}";
131 } 113 }
132 return _encoding; 114 return _encoding;
133 } 115 }
134 116
135 String get fullName => _file.getAbsolutePath(); 117 String get fullName => _file.getAbsolutePath();
136 118
137 int get modificationStamp { 119 int get modificationStamp => _file.lastModified();
138 int stamp = _contentCache.getModificationStamp(this);
139 if (stamp != null) {
140 return stamp;
141 }
142 return _file.lastModified();
143 }
144 120
145 String get shortName => _file.getName(); 121 String get shortName => _file.getName();
146 122
147 UriKind get uriKind => _uriKind; 123 UriKind get uriKind => _uriKind;
148 124
149 int get hashCode => _file.hashCode; 125 int get hashCode => _file.hashCode;
150 126
151 bool get isInSystemLibrary => identical(_uriKind, UriKind.DART_URI); 127 bool get isInSystemLibrary => identical(_uriKind, UriKind.DART_URI);
152 128
153 Source resolveRelative(Uri containedUri) { 129 Source resolveRelative(Uri containedUri) {
154 try { 130 try {
155 Uri resolvedUri = file.toURI().resolveUri(containedUri); 131 Uri resolvedUri = file.toURI().resolveUri(containedUri);
156 return new FileBasedSource.con2(_contentCache, new JavaFile.fromUri(resolv edUri), _uriKind); 132 return new FileBasedSource.con2(new JavaFile.fromUri(resolvedUri), _uriKin d);
157 } on JavaException catch (exception) { 133 } on JavaException catch (exception) {
158 } 134 }
159 return null; 135 return null;
160 } 136 }
161 137
162 String toString() { 138 String toString() {
163 if (_file == null) { 139 if (_file == null) {
164 return "<unknown source>"; 140 return "<unknown source>";
165 } 141 }
166 return _file.getAbsolutePath(); 142 return _file.getAbsolutePath();
167 } 143 }
168 144
169 /** 145 /**
170 * Get the contents of underlying file and pass it to the given receiver. Exac tly one of the 146 * Get the contents and timestamp of the underlying file.
171 * methods defined on the receiver will be invoked unless an exception is thro wn. The method that 147 *
172 * will be invoked depends on which of the possible representations of the con tents is the most 148 * Clients should consider using the the method [AnalysisContext#getContents]
173 * efficient. Whichever method is invoked, it will be invoked before this meth od returns. 149 * because contexts can have local overrides of the content of a source that t he source is not
150 * aware of.
151 *
152 * @return the contents of the source paired with the modification stamp of th e source
153 * @throws Exception if the contents of this source could not be accessed
154 * @see #getContents()
155 */
156 TimestampedData<String> get contentsFromFile {
157 return new TimestampedData<String>(_file.lastModified(), _file.readAsStringS ync());
158 }
159
160 /**
161 * Get the contents of underlying file and pass it to the given receiver.
174 * 162 *
175 * @param receiver the content receiver to which the content of this source wi ll be passed 163 * @param receiver the content receiver to which the content of this source wi ll be passed
176 * @throws Exception if the contents of this source could not be accessed 164 * @throws Exception if the contents of this source could not be accessed
177 * @see #getContents(com.google.dart.engine.source.Source.ContentReceiver) 165 * @see #getContentsToReceiver(ContentReceiver)
178 */ 166 */
179 void getContentsFromFile(Source_ContentReceiver receiver) { 167 void getContentsFromFileToReceiver(Source_ContentReceiver receiver) {
180 { 168 throw new UnsupportedOperationException();
181 }
182 receiver.accept(file.readAsStringSync(), file.lastModified());
183 } 169 }
184 170
185 /** 171 /**
186 * Return the file represented by this source. This is an internal method that is only intended to 172 * Return the file represented by this source. This is an internal method that is only intended to
187 * be used by [UriResolver]. 173 * be used by subclasses of [UriResolver] that are designed to work with file- based sources.
188 * 174 *
189 * @return the file represented by this source 175 * @return the file represented by this source
190 */ 176 */
191 JavaFile get file => _file; 177 JavaFile get file => _file;
192 } 178 }
193 179
194 /** 180 /**
195 * Instances of the class `PackageUriResolver` resolve `package` URI's in the co ntext of 181 * Instances of the class `PackageUriResolver` resolve `package` URI's in the co ntext of
196 * an application. 182 * an application.
197 * 183 *
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 * @param packagesDirectories the package directories that `package` URI's are assumed to be 218 * @param packagesDirectories the package directories that `package` URI's are assumed to be
233 * relative to 219 * relative to
234 */ 220 */
235 PackageUriResolver(List<JavaFile> packagesDirectories) { 221 PackageUriResolver(List<JavaFile> packagesDirectories) {
236 if (packagesDirectories.length < 1) { 222 if (packagesDirectories.length < 1) {
237 throw new IllegalArgumentException("At least one package directory must be provided"); 223 throw new IllegalArgumentException("At least one package directory must be provided");
238 } 224 }
239 this._packagesDirectories = packagesDirectories; 225 this._packagesDirectories = packagesDirectories;
240 } 226 }
241 227
242 Source fromEncoding(ContentCache contentCache, UriKind kind, Uri uri) { 228 Source fromEncoding(UriKind kind, Uri uri) {
243 if (identical(kind, UriKind.PACKAGE_SELF_URI) || identical(kind, UriKind.PAC KAGE_URI)) { 229 if (identical(kind, UriKind.PACKAGE_SELF_URI) || identical(kind, UriKind.PAC KAGE_URI)) {
244 return new FileBasedSource.con2(contentCache, new JavaFile.fromUri(uri), k ind); 230 return new FileBasedSource.con2(new JavaFile.fromUri(uri), kind);
245 } 231 }
246 return null; 232 return null;
247 } 233 }
248 234
249 Source resolveAbsolute(ContentCache contentCache, Uri uri) { 235 Source resolveAbsolute(Uri uri) {
250 if (!isPackageUri(uri)) { 236 if (!isPackageUri(uri)) {
251 return null; 237 return null;
252 } 238 }
253 String path = uri.path; 239 String path = uri.path;
254 if (path == null) { 240 if (path == null) {
255 path = uri.path; 241 path = uri.path;
256 if (path == null) { 242 if (path == null) {
257 return null; 243 return null;
258 } 244 }
259 } 245 }
(...skipping 10 matching lines...) Expand all
270 } else { 256 } else {
271 // <pkgName>/<relPath> 257 // <pkgName>/<relPath>
272 pkgName = path.substring(0, index); 258 pkgName = path.substring(0, index);
273 relPath = path.substring(index + 1); 259 relPath = path.substring(index + 1);
274 } 260 }
275 for (JavaFile packagesDirectory in _packagesDirectories) { 261 for (JavaFile packagesDirectory in _packagesDirectories) {
276 JavaFile resolvedFile = new JavaFile.relative(packagesDirectory, path); 262 JavaFile resolvedFile = new JavaFile.relative(packagesDirectory, path);
277 if (resolvedFile.exists()) { 263 if (resolvedFile.exists()) {
278 JavaFile canonicalFile = getCanonicalFile(packagesDirectory, pkgName, re lPath); 264 JavaFile canonicalFile = getCanonicalFile(packagesDirectory, pkgName, re lPath);
279 UriKind uriKind = isSelfReference(packagesDirectory, canonicalFile) ? Ur iKind.PACKAGE_SELF_URI : UriKind.PACKAGE_URI; 265 UriKind uriKind = isSelfReference(packagesDirectory, canonicalFile) ? Ur iKind.PACKAGE_SELF_URI : UriKind.PACKAGE_URI;
280 return new FileBasedSource.con2(contentCache, canonicalFile, uriKind); 266 return new FileBasedSource.con2(canonicalFile, uriKind);
281 } 267 }
282 } 268 }
283 return new FileBasedSource.con2(contentCache, getCanonicalFile(_packagesDire ctories[0], pkgName, relPath), UriKind.PACKAGE_URI); 269 return new FileBasedSource.con2(getCanonicalFile(_packagesDirectories[0], pk gName, relPath), UriKind.PACKAGE_URI);
284 } 270 }
285 271
286 Uri restoreAbsolute(Source source) { 272 Uri restoreAbsolute(Source source) {
287 if (source is FileBasedSource) { 273 if (source is FileBasedSource) {
288 String sourcePath = source.file.getPath(); 274 String sourcePath = source.file.getPath();
289 for (JavaFile packagesDirectory in _packagesDirectories) { 275 for (JavaFile packagesDirectory in _packagesDirectories) {
290 List<JavaFile> pkgFolders = packagesDirectory.listFiles(); 276 List<JavaFile> pkgFolders = packagesDirectory.listFiles();
291 if (pkgFolders != null) { 277 if (pkgFolders != null) {
292 for (JavaFile pkgFolder in pkgFolders) { 278 for (JavaFile pkgFolder in pkgFolders) {
293 try { 279 try {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 static String FILE_SCHEME = "file"; 404 static String FILE_SCHEME = "file";
419 405
420 /** 406 /**
421 * Return `true` if the given URI is a `file` URI. 407 * Return `true` if the given URI is a `file` URI.
422 * 408 *
423 * @param uri the URI being tested 409 * @param uri the URI being tested
424 * @return `true` if the given URI is a `file` URI 410 * @return `true` if the given URI is a `file` URI
425 */ 411 */
426 static bool isFileUri(Uri uri) => uri.scheme == FILE_SCHEME; 412 static bool isFileUri(Uri uri) => uri.scheme == FILE_SCHEME;
427 413
428 Source fromEncoding(ContentCache contentCache, UriKind kind, Uri uri) { 414 Source fromEncoding(UriKind kind, Uri uri) {
429 if (identical(kind, UriKind.FILE_URI)) { 415 if (identical(kind, UriKind.FILE_URI)) {
430 return new FileBasedSource.con2(contentCache, new JavaFile.fromUri(uri), k ind); 416 return new FileBasedSource.con2(new JavaFile.fromUri(uri), kind);
431 } 417 }
432 return null; 418 return null;
433 } 419 }
434 420
435 Source resolveAbsolute(ContentCache contentCache, Uri uri) { 421 Source resolveAbsolute(Uri uri) {
436 if (!isFileUri(uri)) { 422 if (!isFileUri(uri)) {
437 return null; 423 return null;
438 } 424 }
439 return new FileBasedSource.con1(contentCache, new JavaFile.fromUri(uri)); 425 return new FileBasedSource.con1(new JavaFile.fromUri(uri));
440 } 426 }
441 } 427 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698